Package org.codehaus.jackson.map.module

Examples of org.codehaus.jackson.map.module.SimpleModule


     * Serializer should get passed property context even if contained in a Collection.
     */
    public void testMethodAnnotationInMap() throws Exception
    {
        ObjectMapper mapper = new ObjectMapper();
        SimpleModule module = new SimpleModule("test", Version.unknownVersion());
        module.addSerializer(String.class, new AnnotatedContextualSerializer());
        mapper.registerModule(module);
        ContextualMapBean map = new ContextualMapBean();
        map.beans.put("first", "In Map");
        assertEquals("{\"beans\":{\"first\":\"map->In Map\"}}", mapper.writeValueAsString(map));
    }
View Full Code Here


    // [JACKSON-647]: is resolve() called for contextual instances?
    public void testResolveOnContextual() throws Exception
    {
        ObjectMapper mapper = new ObjectMapper();
        SimpleModule module = new SimpleModule("test", Version.unknownVersion());
        module.addSerializer(String.class, new ContextualAndResolvable());
        mapper.registerModule(module);
        assertEquals(quote("contextual=true,resolved=true"), mapper.writeValueAsString("abc"));
    }
View Full Code Here

    private static ObjectMapper createObjectMapper() {
        // it's a shame that the serialization and deserialization mechanism
        // used aren't symmetric... but it works.
        final DeserializerProvider deserializerProvider = new StdDeserializerProvider(new JsonRepresentationDeserializerFactory());
        final ObjectMapper objectMapper = new ObjectMapper(null, null, deserializerProvider);
        final SimpleModule jsonModule = new SimpleModule("json", new Version(1, 0, 0, null));
        jsonModule.addSerializer(JsonRepresentation.class, new JsonRepresentationSerializer());
        objectMapper.registerModule(jsonModule);

        objectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
        objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        return objectMapper;
View Full Code Here

    static ObjectMapper mapper;

    @BeforeClass
    public static void createMapper() {
        mapper = new ObjectMapper();
        SimpleModule module = new SimpleModule("whatevs", new Version(0, 0, 0, null));
        module.addSerializer(new ConnectionCredentialsSerializer());
        mapper.registerModule(module);
    }
View Full Code Here

    static ObjectMapper mapper;

    @BeforeClass
    public static void createMapper() {
        mapper = new ObjectMapper();
        SimpleModule module = new SimpleModule("whatevs", new Version(0, 0, 0, null));
        module.addSerializer(new ConnectionCredentialsSerializer());
        module.addDeserializer(ConnectionCredentials.class, new ConnectionCredentialsDeserializer());
        mapper.registerModule(module);
    }
View Full Code Here

    static ObjectMapper mapper;

    @BeforeClass
    public static void createMapper() {
        mapper = new ObjectMapper();
        SimpleModule module = new SimpleModule("whatevs", new Version(0, 0, 0, null));
        module.addSerializer(new ObjectIdSerializer());
        module.addDeserializer(ObjectId.class, new ObjectIdDeserializer());
        mapper.registerModule(module);
    }
View Full Code Here

        mapper.getSerializationConfig().setSerializationInclusion(
                JsonSerialize.Inclusion.NON_NULL);
        mapper.configure(
                SerializationConfig.Feature.INDENT_OUTPUT, true);
       
        SimpleModule conversionModule = new SimpleModule("ConversionsModule", new Version(1, 0, 0, null))
            .addSerializer(Money.class, new MoneySerializer())
            .addSerializer(DecimalQuantity.class, new DecimalQuantitySerializer())
            .addSerializer(Percentage.class, new PercentageSerializer())
            .addDeserializer(Percentage.class, new PercentageDeserializer())
            .addSerializer(DateTime.class, new DateTimeSerializer());
View Full Code Here

    }

    protected DataWrapper convertJsonToDataWrapper(String json) {
        ObjectMapper mapper = new ObjectMapper();
        DataDTODeserializer dtoDeserializer = new DataDTODeserializer();
        SimpleModule module = new SimpleModule("DataDTODeserializerModule", new Version(1, 0, 0, null));
        module.addDeserializer(DataDTO.class, dtoDeserializer);
        mapper.registerModule(module);
        if (json == null || "[]".equals(json)){
            return null;
        }
View Full Code Here

     * @throws IOException
     */
    protected DataWrapper convertJsonToDataWrapper(String json) {
        ObjectMapper mapper = new ObjectMapper();
        DataDTODeserializer dtoDeserializer = new DataDTODeserializer();
        SimpleModule module = new SimpleModule("DataDTODeserializerModule", new Version(1, 0, 0, null));
        module.addDeserializer(DataDTO.class, dtoDeserializer);
        mapper.registerModule(module);
        try {
            return mapper.readValue(json, DataWrapper.class);
        } catch (IOException e) {
            throw new RuntimeException(e);
View Full Code Here

    /**
     * Create our customized object mapper that f.ex. takes care
     * 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

Related Classes of org.codehaus.jackson.map.module.SimpleModule

Copyright © 2018 www.massapicom. 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.