val ret = ctCls.toClassImpl(inputType.classLoader, inputType.protectionDomain)
return ret as Class<? extends BindingCodec<Map<QName,Object>, Object>>;
}
+ if (returnType.name == 'char[]') {
+ val ctCls = createUnionImplementation(inputType, typeSpec);
+ val ret = ctCls.toClassImpl(inputType.classLoader, inputType.protectionDomain)
+ return ret as Class<? extends BindingCodec<Map<QName,Object>, Object>>;
+ }
val ctCls = createClass(typeSpec.codecClassName) [
//staticField(Map,"AUGMENTATION_SERIALIZERS");
}
+ def createUnionImplementation(Class<?> inputType, GeneratedTransferObject typeSpec) {
+ return createClass(typeSpec.codecClassName) [
+ val properties = typeSpec.allProperties;
+ //staticField(Map,"AUGMENTATION_SERIALIZERS");
+ if (inputType.isYangBindingAvailable) {
+ implementsType(BINDING_CODEC)
+ staticField(it, INSTANCE_IDENTIFIER_CODEC, BindingCodec)
+ staticField(it, IDENTITYREF_CODEC, BindingCodec)
+ implementsType(BindingDeserializer.asCtClass)
+ }
+ method(Object, "toDomValue", Object) [
+ modifiers = PUBLIC + FINAL + STATIC
+ val ctSpec = inputType.asCtClass;
+ bodyChecked = '''
+ {
+ //System.out.println("«inputType.simpleName»#toDomValue: "+$1);
+
+ if($1 == null) {
+ return null;
+ }
+ «typeSpec.resolvedName» _value = («typeSpec.resolvedName») $1;
+ «FOR property : properties.entrySet»
+ «IF property.key != "getValue"»
+ «property.value.resolvedName» «property.key» = («property.value.resolvedName») _value.«property.key»();
+ if(«property.key» != null) {
+ return «serializeValue(property.value, property.key)»;
+ }
+ «ENDIF»
+ «ENDFOR»
+
+ return null;
+ }
+ '''
+ ]
+ method(Object, "serialize", Object) [
+ bodyChecked = '''
+ {
+ return toDomValue($1);
+ }
+ '''
+ ]
+ method(Object, "fromDomValue", Object) [
+ modifiers = PUBLIC + FINAL + STATIC
+ bodyChecked = '''
+ {
+ //System.out.println("«inputType.simpleName»#fromDomValue: "+$1);
+
+ if($1 == null) {
+ return null;
+ }
+ if($1 instanceof String) {
+ String _simpleValue = (String) $1;
+ return new «typeSpec.resolvedName»(_simpleValue.toCharArray());
+ }
+ return null;
+ }
+ '''
+ ]
+ method(Object, "deserialize", Object) [
+ bodyChecked = '''{
+ return fromDomValue($1);
+ }
+ '''
+ ]
+ ]
+ }
+
def boolean isYangBindingAvailable(Class<?> class1) {
try {
val bindingCodecClass = class1.classLoader.loadClass(BINDING_CODEC.name);
} else if (CLASS_TYPE.equals(signature)) {
return '''(«QName.resolvedName») «IDENTITYREF_CODEC».serialize(«property»)'''
}
+ if ("char[]" == signature.name) {
+ return '''new String(«property»)''';
+ }
return '''«property»''';
}
--- /dev/null
+package org.opendaylight.controller.sal.binding.test.bugfix;
+
+import org.junit.Test;
+import org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.igp.node.attributes.Prefix;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.igp.node.attributes.PrefixBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.CompositeNode;
+
+
+
+
+
+
+
+
+import static org.junit.Assert.*;
+
+public class UnionSerializationTest extends AbstractDataServiceTest {
+
+ public static final String PREFIX_STRING = "192.168.0.1/32";
+
+
+ @Test
+ public void testPrefixSerialization() throws Exception {
+
+ Ipv4Prefix ipv4prefix = new Ipv4Prefix(PREFIX_STRING);
+ IpPrefix ipPrefix = new IpPrefix(ipv4prefix);
+ Prefix prefix = new PrefixBuilder().setPrefix(ipPrefix).build();
+
+ CompositeNode serialized = testContext.getBindingToDomMappingService().toDataDom(prefix);
+ assertNotNull(serialized);
+ assertNotNull(serialized.getFirstSimpleByName(Prefix.QNAME));
+ assertEquals(PREFIX_STRING, serialized.getFirstSimpleByName(Prefix.QNAME).getValue());
+
+ Prefix deserialized = (Prefix) testContext.getBindingToDomMappingService().dataObjectFromDataDom(InstanceIdentifier.builder().node(Prefix.class).build(), serialized);
+ assertNotNull(deserialized);
+ assertNotNull(deserialized.getPrefix());
+ assertNotNull(deserialized.getPrefix().getIpv4Prefix());
+ assertEquals(PREFIX_STRING, deserialized.getPrefix().getIpv4Prefix().getValue());
+ }
+
+}