use of com.github.davidmoten.odata.client.internal.UnmappedFieldsImpl in project odata-client by davidmoten.
the class Serializer method deserializeToCollection.
private <T> CollectionInfo<T> deserializeToCollection(String json, Class<T> cls, ContextPath contextPath) {
try {
ObjectMapper m = MAPPER_EXCLUDE_NULLS;
ObjectNode o = m.readValue(json, ObjectNode.class);
List<T> list = new ArrayList<T>();
for (JsonNode item : o.get("value")) {
String text = m.writeValueAsString(item);
Class<? extends T> subClass = RequestHelper.getSubClass(contextPath, contextPath.context().schemas(), cls, text);
list.add(deserialize(text, subClass, contextPath, true));
}
// TODO support relative urls using odata.context if present
Optional<String> nextLink = Optional.ofNullable(o.get("@odata.nextLink")).map(JsonNode::asText);
Optional<String> deltaLink = Optional.ofNullable(o.get("@odata.deltaLink")).map(JsonNode::asText);
@SuppressWarnings("unchecked") Map<String, Object> map = m.convertValue(o, HashMap.class);
UnmappedFieldsImpl u = new UnmappedFieldsImpl();
for (String fieldName : map.keySet()) {
if (!COLLECTION_PAGE_FIELDS.contains(fieldName)) {
u.put(fieldName, map.get(fieldName));
}
}
return new CollectionInfo<T>(list, nextLink, deltaLink, u);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
Aggregations