use of com.fasterxml.jackson.databind.BeanProperty in project alfresco-remote-api by Alfresco.
the class TargetDeserializer method deserialize.
@Override
public Target deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
Target target = null;
JsonToken curr = jp.getCurrentToken();
if (curr == JsonToken.START_OBJECT) {
while (jp.nextToken() != JsonToken.END_OBJECT) {
String fieldname = jp.getCurrentName();
if (Type.SITE.toString().equals(fieldname.toUpperCase())) {
jp.nextToken();
try {
JavaType t = SimpleType.construct(Site.class);
BeanProperty p = new BeanProperty.Std(new PropertyName(""), t, null, null, null, null);
JsonDeserializer<?> siteDeserializer = ctxt.findContextualValueDeserializer(t, p);
Site site = (Site) siteDeserializer.deserialize(jp, ctxt);
target = new SiteTarget(site);
} catch (JsonMappingException e) {
throw new IllegalArgumentException("Target body is invalid for target type");
}
} else if (Type.FILE.toString().equals(fieldname.toUpperCase())) {
jp.nextToken();
try {
JavaType t = SimpleType.construct(Document.class);
BeanProperty p = new BeanProperty.Std(new PropertyName(""), t, null, null, null, null);
JsonDeserializer<?> documentDeserializer = ctxt.findContextualValueDeserializer(t, p);
Document document = (Document) documentDeserializer.deserialize(jp, ctxt);
target = new DocumentTarget(document);
} catch (JsonMappingException e) {
throw new IllegalArgumentException("Target body is invalid for target type");
}
} else if (Type.FOLDER.toString().equals(fieldname.toUpperCase())) {
jp.nextToken();
try {
JavaType t = SimpleType.construct(Folder.class);
BeanProperty p = new BeanProperty.Std(new PropertyName(""), t, null, null, null, null);
JsonDeserializer<?> folderDeserializer = ctxt.findContextualValueDeserializer(t, p);
Folder folder = (Folder) folderDeserializer.deserialize(jp, ctxt);
target = new FolderTarget(folder);
} catch (JsonMappingException e) {
throw new IllegalArgumentException("Target body is invalid for target type");
}
}
}
return target;
} else {
throw new IOException("Unable to deserialize favourite: " + curr.asString());
}
}
Aggregations