use of org.osgi.util.converter.Converter in project felix by apache.
the class JsonBackingObjectSerializationTest method testComplexMapSerializationUsingRule.
@Test
public void testComplexMapSerializationUsingRule() {
final Converter converter = Converters.newConverterBuilder().rule(new MapTargetRule()).build();
final JsonWriterFactory factory = new JsonWriterFactory();
final String actual = new JsonSerializerImpl().serialize(MyDTOishObject.factory("A", "B")).convertWith(converter).writeWith(factory.newDebugWriter(converter)).toString();
assertEquals(EXPECTED, actual);
}
use of org.osgi.util.converter.Converter in project felix by apache.
the class YamlSerializerTest method testCodecWithAdapter.
@Test
public void testCodecWithAdapter() {
Map<String, Foo> m1 = new HashMap<>();
m1.put("f", new Foo("fofofo"));
Map<String, Map<String, Foo>> m = new HashMap<>();
m.put("submap", m1);
Converter ca = converter.newConverterBuilder().rule(new TypeRule<Foo, String>(Foo.class, String.class, Foo::tsFun)).rule(new TypeRule<String, Foo>(String.class, Foo.class, v -> Foo.fsFun(v))).build();
YamlSerializerImpl yamlCodec = new YamlSerializerImpl();
String yaml = yamlCodec.serialize(m).convertWith(ca).toString();
assertEquals("submap: \n" + " f: '<fofofo>'", yaml);
// And convert back
Map<String, Map<String, Foo>> m2 = yamlCodec.deserialize(new TypeReference<Map<String, Map<String, Foo>>>() {
}).convertWith(ca).from(yaml);
assertEquals(m, m2);
}
Aggregations