Fix JSON parser NPE
This commit is contained in:
parent
ca0929df07
commit
80c13494a8
|
@ -126,7 +126,7 @@ public class StringDt extends BasePrimitive<String> implements IQueryParameterTy
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return super.isEmpty() && StringUtils.isBlank(getValue());
|
return super.isBaseEmpty() && StringUtils.isBlank(getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -971,9 +971,10 @@ public class JsonParser extends BaseParser implements IParser {
|
||||||
theEventWriter.writeStartObject();
|
theEventWriter.writeStartObject();
|
||||||
theEventWriter.write("url", ext.getUrl().getValue());
|
theEventWriter.write("url", ext.getUrl().getValue());
|
||||||
|
|
||||||
if (value == null && ext.getAllUndeclaredExtensions().isEmpty()) {
|
boolean noValue = value == null || value.isEmpty();
|
||||||
|
if (noValue && ext.getAllUndeclaredExtensions().isEmpty()) {
|
||||||
ourLog.debug("Extension with URL[{}] has no value", ext.getUrl().getValue());
|
ourLog.debug("Extension with URL[{}] has no value", ext.getUrl().getValue());
|
||||||
} else if (value == null) {
|
} else if (noValue) {
|
||||||
theEventWriter.writeStartArray("extension");
|
theEventWriter.writeStartArray("extension");
|
||||||
for (ExtensionDt next : ext.getUndeclaredExtensions()) {
|
for (ExtensionDt next : ext.getUndeclaredExtensions()) {
|
||||||
writeUndeclaredExt(theResDef, theResource, theEventWriter, next);
|
writeUndeclaredExt(theResDef, theResource, theEventWriter, next);
|
||||||
|
|
|
@ -558,7 +558,7 @@ public class RestfulServer extends HttpServlet {
|
||||||
statusCode=((BaseServerResponseException) e).getStatusCode();
|
statusCode=((BaseServerResponseException) e).getStatusCode();
|
||||||
issue.getDetails().setValue(e.getMessage());
|
issue.getDetails().setValue(e.getMessage());
|
||||||
} else {
|
} else {
|
||||||
ourLog.error("Failure during REST processing: {}"+ e.toString(), e);
|
ourLog.error("Failure during REST processing", e);
|
||||||
issue.getDetails().setValue(e.toString() + "\n\n" + ExceptionUtils.getStackTrace(e));
|
issue.getDetails().setValue(e.toString() + "\n\n" + ExceptionUtils.getStackTrace(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package ca.uhn.fhir.model.primitive;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class StringDtTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBlank() {
|
||||||
|
|
||||||
|
assertTrue(new StringDt("").isEmpty());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -68,12 +68,24 @@ public class JsonParserTest {
|
||||||
@Test
|
@Test
|
||||||
public void testEncodingNullExtension() {
|
public void testEncodingNullExtension() {
|
||||||
Patient p = new Patient();
|
Patient p = new Patient();
|
||||||
p.addUndeclaredExtension(new ExtensionDt(false, "http://foo#bar"));
|
ExtensionDt extension = new ExtensionDt(false, "http://foo#bar");
|
||||||
String str = new FhirContext().newJsonParser().encodeResourceToString(p);
|
p.addUndeclaredExtension(extension);
|
||||||
|
String str = ourCtx.newJsonParser().encodeResourceToString(p);
|
||||||
|
|
||||||
assertEquals("{\"resourceType\":\"Patient\",\"extension\":[{\"url\":\"http://foo#bar\"}]}", str);
|
assertEquals("{\"resourceType\":\"Patient\",\"extension\":[{\"url\":\"http://foo#bar\"}]}", str);
|
||||||
|
|
||||||
|
extension.setValue(new StringDt());
|
||||||
|
|
||||||
|
str = ourCtx.newJsonParser().encodeResourceToString(p);
|
||||||
|
assertEquals("{\"resourceType\":\"Patient\",\"extension\":[{\"url\":\"http://foo#bar\"}]}", str);
|
||||||
|
|
||||||
|
extension.setValue(new StringDt(""));
|
||||||
|
|
||||||
|
str = ourCtx.newJsonParser().encodeResourceToString(p);
|
||||||
|
assertEquals("{\"resourceType\":\"Patient\",\"extension\":[{\"url\":\"http://foo#bar\"}]}", str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeBinaryResource() {
|
public void testEncodeBinaryResource() {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue