Fixed unmarshaller
This commit is contained in:
parent
c48eae1355
commit
c36d76c19c
|
@ -23,6 +23,7 @@ import org.gcube.com.fasterxml.jackson.databind.JsonMappingException;
|
|||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.gcube.com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import org.gcube.com.fasterxml.jackson.databind.exc.InvalidTypeIdException;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.TextNode;
|
||||
|
@ -305,7 +306,7 @@ public abstract class ElementMapper {
|
|||
throws JsonParseException, JsonMappingException, IOException {
|
||||
try {
|
||||
return mapper.readValue(reader, clz);
|
||||
} catch (JsonMappingException e) {
|
||||
} catch (InvalidTypeIdException e) {
|
||||
if(!ModelElement.class.isAssignableFrom(clz)) {
|
||||
throw e;
|
||||
}
|
||||
|
@ -329,7 +330,7 @@ public abstract class ElementMapper {
|
|||
throws JsonParseException, JsonMappingException, IOException {
|
||||
try {
|
||||
return mapper.readValue(stream, clz);
|
||||
} catch (JsonMappingException e) {
|
||||
} catch (InvalidTypeIdException e) {
|
||||
if(!ModelElement.class.isAssignableFrom(clz)) {
|
||||
throw e;
|
||||
}
|
||||
|
@ -352,7 +353,7 @@ public abstract class ElementMapper {
|
|||
throws JsonParseException, JsonMappingException, IOException {
|
||||
try {
|
||||
return mapper.readValue(string, clz);
|
||||
} catch (JsonMappingException e) {
|
||||
} catch (InvalidTypeIdException e) {
|
||||
if(!ModelElement.class.isAssignableFrom(clz)) {
|
||||
throw e;
|
||||
}
|
||||
|
@ -367,7 +368,7 @@ public abstract class ElementMapper {
|
|||
JavaType type = mapper.getTypeFactory().constructCollectionType(ArrayList.class, clz);
|
||||
try {
|
||||
return mapper.readValue(string, type);
|
||||
} catch (JsonMappingException e) {
|
||||
} catch (InvalidTypeIdException e) {
|
||||
if(!ModelElement.class.isAssignableFrom(clz)) {
|
||||
throw e;
|
||||
}
|
||||
|
@ -386,7 +387,7 @@ public abstract class ElementMapper {
|
|||
JavaType type = mapper.getTypeFactory().constructCollectionType(ArrayList.class, Element.class);
|
||||
try {
|
||||
return mapper.readValue(string, type);
|
||||
} catch (JsonMappingException e) {
|
||||
} catch (InvalidTypeIdException e) {
|
||||
List<El> ret = new ArrayList<>();
|
||||
ArrayNode arrayNode = (ArrayNode) mapper.readTree(string);
|
||||
for(JsonNode jsonNode : arrayNode) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.gcube.informationsystem.types;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.base.reference.Element;
|
||||
import org.gcube.informationsystem.base.reference.IdentifiableElement;
|
||||
|
@ -245,4 +246,20 @@ public class SerializationTest {
|
|||
public void testVersionNotHighest() throws Exception{
|
||||
TypeMapper.serializeType(TestVersionNotHighest.class);
|
||||
}
|
||||
|
||||
public static final String PG_OK = "{\"type\":\"PropagationConstraint\",\"add\":\"propagate\",\"delete\":\"cascade\",\"remove\":\"cascadeWhenOrphan\"}";
|
||||
public static final String PG_NO = "{\"type\":\"PropagationConstraint\",\"add\":\"propagate\",\"delete\":\"propagate\",\"remove\":\"cascadeWhenOrphan\"}";
|
||||
public static final String PG_EXT = "{\"type\":\"MyPropagationConstraint\",\"supertypes\":[\"PropagationConstraint\",\"Property\"], \"add\":\"propagate\",\"delete\":\"cascade\",\"remove\":\"cascadeWhenOrphan\"}";
|
||||
|
||||
@Test
|
||||
public void testPropagationConstraintMarshalling() throws Exception {
|
||||
ElementMapper.unmarshal(PropagationConstraint.class, PG_OK);
|
||||
ElementMapper.unmarshal(PropagationConstraint.class, PG_EXT);
|
||||
}
|
||||
|
||||
@Test(expected = JsonMappingException.class)
|
||||
public void testWrongPropagationConstraintMarshalling() throws Exception {
|
||||
ElementMapper.unmarshal(PropagationConstraint.class, PG_NO);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue