Examples of addKeySerializer()


Examples of com.fasterxml.jackson.databind.module.SimpleModule.addKeySerializer()

    public void testSimpleKeySer() throws Exception
    {
        ObjectMapper mapper = new ObjectMapper();
        SimpleModule module = new SimpleModule("test", Version.unknownVersion());
        module.addKeySerializer(String.class, new ContextualKeySerializer("prefix"));
        mapper.registerModule(module);
        Map<String,Object> input = new HashMap<String,Object>();
        input.put("a", Integer.valueOf(3));
        String json = mapper.writerWithType(TypeFactory.defaultInstance().constructMapType(HashMap.class, String.class, Object.class))
            .writeValueAsString(input);
View Full Code Here

Examples of com.fasterxml.jackson.databind.module.SimpleModule.addKeySerializer()

    // Test custom key serializer for enum
    public void testCustomForEnum() throws IOException
    {
        final ObjectMapper mapper = new ObjectMapper();
        SimpleModule mod = new SimpleModule("test");
        mod.addKeySerializer(ABC.class, new ABCSerializer());
        mapper.registerModule(mod);

        String json = mapper.writeValueAsString(new ABCMapWrapper());
        assertEquals("{\"stuff\":{\"xxxB\":\"bar\"}}", json);
    }
View Full Code Here

Examples of org.codehaus.jackson.map.module.SimpleModule.addKeySerializer()

    public void testSimpleKeySer() throws Exception
    {
        ObjectMapper mapper = new ObjectMapper();
        SimpleModule module = new SimpleModule("test", Version.unknownVersion());
        module.addKeySerializer(String.class, new ContextualKeySerializer("prefix"));
        mapper.registerModule(module);
        Map<String,Object> input = new HashMap<String,Object>();
        input.put("a", Integer.valueOf(3));
        String json = mapper.writerWithType(TypeFactory.defaultInstance().constructMapType(HashMap.class, String.class, Object.class))
            .writeValueAsString(input);
View Full Code Here

Examples of org.codehaus.jackson.map.module.SimpleModule.addKeySerializer()

     * of removing invalid characters from map keys.
     */
    private static ObjectMapper createCustomizedObjectMapper() {
        SimpleModule mapKeyModule =  new SimpleModule("MyMapKeySanitizingSerializerModule"
                , new Version(1, 0, 0, null));
        mapKeyModule.addKeySerializer(String.class, new KeySanitizingSerializer());

        final ObjectMapper customizedMapper = new ObjectMapper();
        customizedMapper.registerModule(mapKeyModule);

        // The following code has been copied from JacksonDBCollection and
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.