use of org.qi4j.api.value.ValueSerializationException in project qi4j-sdk by Qi4j.
the class ValueDeserializerAdapter method deserializeNodeValueComposite.
private <T> T deserializeNodeValueComposite(ValueType valueType, InputNodeType inputNode) throws Exception {
ValueCompositeType valueCompositeType = (ValueCompositeType) valueType;
Class<?> valueBuilderType = first(valueCompositeType.types());
String typeInfo = this.<String>getObjectFieldValue(inputNode, "_type", this.<String>buildDeserializeInputNodeFunction(new ValueType(String.class)));
TREE_PARSING_LOG.trace("In deserializeNodeValueComposite(), getObjectFieldValue( {} ) returned '{}'", inputNode, typeInfo);
if (typeInfo != null) {
ValueDescriptor valueDescriptor = valuesModule().valueDescriptor(typeInfo);
if (valueDescriptor == null) {
throw new ValueSerializationException("Specified value type could not be resolved: " + typeInfo);
}
valueCompositeType = valueDescriptor.valueType();
valueBuilderType = Class.forName(typeInfo);
if (!valueType.equals(valueCompositeType)) {
TREE_PARSING_LOG.debug("Overriding {} with {} as defined in _type field.", valueType, valueCompositeType);
}
}
return deserializeValueComposite(valueCompositeType, valueBuilderType, inputNode);
}
use of org.qi4j.api.value.ValueSerializationException in project qi4j-sdk by Qi4j.
the class ValueDeserializerAdapter method deserializeNodeGuessed.
@SuppressWarnings("unchecked")
private <T> T deserializeNodeGuessed(ValueType valueType, InputNodeType inputNode) throws Exception {
if (isObjectValue(inputNode)) {
// Attempt ValueComposite deserialization
ValueCompositeType valueCompositeType;
if (// with _type info
objectHasField(inputNode, "_type")) {
String typeInfo = this.<String>getObjectFieldValue(inputNode, "_type", this.<String>buildDeserializeInputNodeFunction(new ValueType(String.class)));
TREE_PARSING_LOG.trace("In deserializeNodeGuessed(), getObjectFieldValue( {} ) returned '{}'", inputNode, typeInfo);
ValueDescriptor valueDescriptor = valuesModule().valueDescriptor(typeInfo);
if (valueDescriptor == null) {
throw new ValueSerializationException("Specified value type could not be resolved: " + typeInfo);
}
valueCompositeType = valueDescriptor.valueType();
TREE_PARSING_LOG.debug("Overriding {} with {} as defined in _type field.", valueType, valueCompositeType);
} else // without _type info
{
ValueDescriptor valueDescriptor = valuesModule().valueDescriptor(first(valueType.types()).getName());
if (valueDescriptor == null) {
throw new ValueSerializationException("Don't know how to deserialize " + inputNode);
}
valueCompositeType = valueDescriptor.valueType();
TREE_PARSING_LOG.debug("Overriding {} with {} as found in available ValueComposites.", valueType, valueCompositeType);
}
Class<?> valueBuilderType = first(valueCompositeType.types());
return deserializeValueComposite(valueCompositeType, valueBuilderType, inputNode);
}
// Last resort : base64 java deserialization
return (T) deserializeBase64Serialized(inputNode);
}
use of org.qi4j.api.value.ValueSerializationException in project qi4j-sdk by Qi4j.
the class OrgJsonValueDeserializer method putArrayNodeInMap.
@Override
protected <K, V> void putArrayNodeInMap(Object inputNode, Function<Object, K> keyDeserializer, Function<Object, V> valueDeserializer, Map<K, V> map) throws Exception {
if (JSONObject.NULL.equals(inputNode)) {
return;
}
if (!(inputNode instanceof JSONArray)) {
throw new ValueSerializationException("Expected an array but got " + inputNode);
}
JSONArray array = (JSONArray) inputNode;
for (int idx = 0; idx < array.length(); idx++) {
Object item = array.get(idx);
if (!(item instanceof JSONObject)) {
throw new ValueSerializationException("Expected an object but got " + inputNode);
}
JSONObject object = (JSONObject) item;
Object keyNode = object.get("key");
Object valueNode = object.get("value");
K key = keyDeserializer.map(keyNode);
V value = valueDeserializer.map(valueNode);
if (key != null) {
map.put(key, value);
}
}
}
use of org.qi4j.api.value.ValueSerializationException in project qi4j-sdk by Qi4j.
the class StaxValueDeserializer method putArrayNodeInMap.
@Override
protected <K, V> void putArrayNodeInMap(Node inputNode, Function<Node, K> keyDeserializer, Function<Node, V> valueDeserializer, Map<K, V> map) throws Exception {
if (inputNode == null) {
return;
}
if (!"array".equals(inputNode.getLocalName())) {
throw new ValueSerializationException("Expected an <array/> but got " + inputNode);
}
NodeList entriesNodes = inputNode.getChildNodes();
for (int idx = 0; idx < entriesNodes.getLength(); idx++) {
Node entryNode = entriesNodes.item(idx);
K key = getObjectFieldValue(entryNode, "key", keyDeserializer);
V value = getObjectFieldValue(entryNode, "value", valueDeserializer);
if (key != null) {
map.put(key, value);
}
}
}
use of org.qi4j.api.value.ValueSerializationException in project qi4j-sdk by Qi4j.
the class StaxValueDeserializer method getObjectFieldNode.
private static Node getObjectFieldNode(Node inputNode, String key) {
if (inputNode == null) {
return null;
}
if (!(inputNode instanceof Element)) {
throw new ValueSerializationException("Excpected an Element but got " + inputNode);
}
NodeList fieldNodes = inputNode.getChildNodes();
for (int idx = 0; idx < fieldNodes.getLength(); idx++) {
Node fieldNode = fieldNodes.item(idx);
Node nameNode = getDirectChildNode(fieldNode, "name");
if (nameNode != null && key.equals(nameNode.getTextContent())) {
return fieldNode;
}
}
return null;
}
Aggregations