use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.DeserializationContext in project snow-owl by b2ihealthcare.
the class ConceptPropertyDeserializer method deserialize.
@Override
public ConceptProperty<?> deserialize(JsonParser parser, DeserializationContext arg1) throws IOException, JsonProcessingException {
TreeNode node = parser.readValueAsTree();
ObjectCodec objectCodec = parser.getCodec();
Iterator<String> fieldNames = node.fieldNames();
PropertyType[] propertyTypes = PropertyType.values();
PropertyType propertyType = null;
while (fieldNames.hasNext()) {
String fieldName = (String) fieldNames.next();
if (fieldName.startsWith(VALUE_PREFIX)) {
String type = fieldName.replace(VALUE_PREFIX, "");
propertyType = Sets.newHashSet(propertyTypes).stream().filter(t -> t.getDisplayName().equalsIgnoreCase(type)).findFirst().orElseThrow(() -> new IllegalArgumentException("Unknown property type '" + fieldName + "'."));
break;
}
}
if (propertyType == null) {
throw new IllegalArgumentException("Invalid property type with null value.");
}
switch(propertyType) {
case CODING:
return objectCodec.treeToValue(node, CodingConceptProperty.class);
case CODE:
return objectCodec.treeToValue(node, CodeConceptProperty.class);
case DATETIME:
return objectCodec.treeToValue(node, DateTimeConceptProperty.class);
case STRING:
return objectCodec.treeToValue(node, StringConceptProperty.class);
case BOOLEAN:
return objectCodec.treeToValue(node, BooleanConceptProperty.class);
case DECIMAL:
return objectCodec.treeToValue(node, DecimalConceptProperty.class);
case INTEGER:
return objectCodec.treeToValue(node, IntegerConceptProperty.class);
default:
throw new IllegalArgumentException("Unsupported property type '" + propertyType + "'.");
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.DeserializationContext in project snow-owl by b2ihealthcare.
the class ExtensionDeserializer method deserialize.
@Override
public Extension<?> deserialize(JsonParser parser, DeserializationContext ctx) throws IOException, JsonProcessingException {
TreeNode node = parser.readValueAsTree();
ObjectCodec objectCodec = parser.getCodec();
Iterator<String> fieldNames = node.fieldNames();
ExtensionType[] extensionTypes = ExtensionType.values();
ExtensionType extensionType = null;
while (fieldNames.hasNext()) {
String fieldName = (String) fieldNames.next();
if (fieldName.startsWith(VALUE_PREFIX)) {
String type = fieldName.replace(VALUE_PREFIX, "");
extensionType = Sets.newHashSet(extensionTypes).stream().filter(t -> t.getDisplayName().equalsIgnoreCase(type)).findFirst().orElseThrow(() -> new IllegalArgumentException("Unknown extension type '" + fieldName + "'."));
break;
}
}
if (extensionType == null) {
throw new IllegalArgumentException("Invalid extension with null value type.");
}
switch(extensionType) {
case INTEGER:
return objectCodec.treeToValue(node, IntegerExtension.class);
case STRING:
return objectCodec.treeToValue(node, StringExtension.class);
default:
throw new IllegalArgumentException("Unsupported extension type '" + extensionType + "'.");
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.DeserializationContext in project cyclops by aol.
the class IterableXDeserializer method deserialize.
@Override
public IterableX<?> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
if (!p.isExpectedStartArrayToken()) {
return (IterableX) ctxt.handleUnexpectedToken(handledType(), p);
}
List multi = new ArrayList();
JsonToken t;
while ((t = p.nextToken()) != JsonToken.END_ARRAY) {
Object value;
if (t == JsonToken.VALUE_NULL) {
value = null;
} else if (typeDeserializerForValue == null) {
value = valueDeserializer.deserialize(p, ctxt);
} else {
value = valueDeserializer.deserializeWithType(p, ctxt, typeDeserializerForValue);
}
multi.add(value);
}
if (Vector.class.isAssignableFrom(elementType))
return Vector.fromIterable(multi);
if (Seq.class.isAssignableFrom(elementType))
return Seq.fromIterable(multi);
if (LazySeq.class.isAssignableFrom(elementType))
return LazySeq.fromIterable(multi);
if (LazyString.class.isAssignableFrom(elementType))
return LazyString.fromLazySeq((LazySeq) LazySeq.fromIterable(multi));
if (IntMap.class.isAssignableFrom(elementType))
return IntMap.fromIterable(multi);
if (ReactiveSeq.class.isAssignableFrom(elementType))
return ReactiveSeq.fromIterable(multi);
if (Streamable.class.isAssignableFrom(elementType))
return Streamable.fromIterable(multi);
if (BankersQueue.class.isAssignableFrom(elementType))
return BankersQueue.fromIterable(multi);
if (Bag.class.isAssignableFrom(elementType))
return Bag.fromIterable(multi);
if (cyclops.data.HashSet.class.isAssignableFrom(elementType))
return HashSet.fromIterable(multi);
if (cyclops.data.TrieSet.class.isAssignableFrom(elementType))
return TrieSet.fromIterable(multi);
if (cyclops.data.TreeSet.class.isAssignableFrom(elementType))
return TreeSet.fromIterable(multi, (Comparator) Comparator.naturalOrder());
Optional<Method> m = streamMethod.computeIfAbsent(elementType, c -> Stream.of(c.getMethods()).filter(method -> "fromIterable".equals(method.getName())).filter(method -> method.getParameterCount() == 1).findFirst().map(m2 -> {
m2.setAccessible(true);
return m2;
}));
IterableX x = m.map(mt -> (IterableX) new Invoker().executeMethod(multi, mt, itX)).orElse(null);
return x;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.DeserializationContext in project cyclops by aol.
the class PersistentMapDeserializer method deserialize.
@Override
public PersistentMap<?, ?> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
JsonDeserializer deser = ctxt.findRootValueDeserializer(ctxt.getTypeFactory().constructRawMapType(Map.class));
Object o = deser.deserialize(p, ctxt);
if (HashMap.class.isAssignableFrom(mapType))
return HashMap.fromMap((Map) o);
if (TreeMap.class.isAssignableFrom(mapType))
return TreeMap.fromMap((Comparator) Comparator.naturalOrder(), (Map) o);
/**
* if(TrieMap.class.isAssignableFrom(mapType))
* return TrieMap.fromMap((Map)o);
* if(LinkedMap.class.isAssignableFrom(mapType))
* return LinkedMap.fromMap((Map)o);
*/
Optional<Method> m = streamMethod.computeIfAbsent(mapType, c -> Stream.of(c.getMethods()).filter(method -> "fromMap".equals(method.getName())).filter(method -> method.getParameterCount() == 1).filter(method -> method.getParameterTypes()[0].isAssignableFrom(Map.class)).findFirst().map(m2 -> {
m2.setAccessible(true);
return m2;
}));
PersistentMap<?, ?> x = m.map(mt -> (PersistentMap) new Invoker().executeMethod(o, mt, mapType)).orElse(null);
return x;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.DeserializationContext in project incubator-servicecomb-java-chassis by apache.
the class ArgWrapperJavaType method readValue.
public Map<String, Object> readValue(ObjectMapper mapper, String json) throws IOException {
Map<String, Object> args = new LinkedHashMap<>();
JsonParser jp = mapper.getFactory().createParser(json);
DeserializationContext deserializationContext = ObjectMapperUtils.createDeserializationContext(mapper, jp);
jp.nextToken();
for (String fieldName = jp.nextFieldName(); fieldName != null; fieldName = jp.nextFieldName()) {
jp.nextToken();
ArgInfo argInfo = argInfos.get(fieldName);
if (argInfo == null) {
continue;
}
if (argInfo.deserializer == null) {
argInfo.deserializer = deserializationContext.findRootValueDeserializer(argInfo.javaType);
}
args.put(fieldName, argInfo.deserializer.deserialize(jp, deserializationContext));
}
return args;
}
Aggregations