private Object getValue(String value){ if(schemaNode != null){ if(schemaNode instanceof LeafListSchemaNode){ return TypeDefinitionAwareCodec .from(LeafListSchemaNode.class.cast(schemaNode).getType()).deserialize(value); } } return value; }
private static String serialize(final @NonNull TypeDefinition<?> type, final @NonNull Object value) { final TypeDefinitionAwareCodec<Object, ?> codec = TypeDefinitionAwareCodec.from(type); if (codec == null) { LOG.warn("Failed to find codec for {}, falling back to using stream", type); return value.toString(); } try { return codec.serialize(value); } catch (ClassCastException e) { LOG.warn("Provided node value {} did not have type {} required by mapping. Using stream instead.", value, type, e); return value.toString(); } }
private static Object domValueFromString(final Codec<Object, Object> codec, final TypeDefinition<?> type, final Object defaultValue) { TypeDefinitionAwareCodec<?, ?> typeDefAwareCodec = TypeDefinitionAwareCodec.from(type); if (typeDefAwareCodec != null) { Object castedDefaultValue = typeDefAwareCodec.deserialize((String) defaultValue); return codec.deserialize(castedDefaultValue); } // FIXME: BUG-4647 Refactor / redesign this to throw hard error, // once BUG-4638 is fixed and will provide proper getDefaultValue implementation. return null; }
private static Object domValueFromString(final Codec<Object, Object> codec, final TypeDefinition<?> type, final Object defaultValue) { final TypeDefinitionAwareCodec<?, ?> typeDefAwareCodec = TypeDefinitionAwareCodec.from(type); if (typeDefAwareCodec != null) { final Object castedDefaultValue = typeDefAwareCodec.deserialize((String) defaultValue); return codec.deserialize(castedDefaultValue); } // FIXME: BUG-4647 Refactor / redesign this to throw hard error, // once BUG-4638 is fixed and will provide proper getDefaultValue implementation. return null; }
} else { final TypeDefinitionAwareCodec<Object, ? extends TypeDefinition<?>> typeAwarecodec = TypeDefinitionAwareCodec .from(type); if (typeAwarecodec != null) { if (input instanceof IdentityValuesDTO) {
private Object getValue(QName key, String value){ if(listSchemaNode != null){ for(DataSchemaNode node : listSchemaNode.getChildNodes()){ if(node instanceof LeafSchemaNode && node.getQName().equals(key)){ return TypeDefinitionAwareCodec.from(LeafSchemaNode.class.cast(node).getType()).deserialize(value); } } } return value; } }
@SuppressWarnings("unchecked") @Override public Object serialize(final Object input) { try { if (type instanceof IdentityrefTypeDefinition) { return identityrefCodec.serialize(input); } else if (type instanceof LeafrefTypeDefinition) { return LEAFREF_DEFAULT_CODEC.serialize(input); } else if (type instanceof InstanceIdentifierTypeDefinition) { return instanceIdentifier.serialize(input); } else { final TypeDefinitionAwareCodec<Object, ? extends TypeDefinition<?>> typeAwarecodec = TypeDefinitionAwareCodec .from(type); if (typeAwarecodec != null) { return typeAwarecodec.serialize(input); } else { logger.debug("Codec for type \"" + type.getQName().getLocalName() + "\" is not implemented yet."); return null; } } } catch (final ClassCastException e) { // TODO remove this catch when everyone use codecs logger.error( "ClassCastException was thrown when codec is invoked with parameter " + String.valueOf(input), e); return input; } }