Skip to content

joongsoo/jackson-module-force-deserializer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jackson-module-force-deserializer

This module is born jackson-databind#2570

This module is support deserialize all possible types by force create. it is possible to deserialize many types that could not be deserialized in existing modules.

@JsonCreator may be used, but this is too cumbersome. And it may be need to serialize class developed by other developers.

Alternatively, the jackson-module-parameter-names module can be choice. but it does not support versions under 8. and it has some limitations that cannot be deserialize.

For example. this class is immutable.

class ImmutableClass {
    private String str;
    
    public ImmutableClass(String someStr) {
        this.str = someStr;
    }

    public String getStr() {
        return str;
    }
}

new ObjectMapper().writeAsString(new SomeClass("Hi"));

This code is serialized as { "str": "Hi" }.

But jackson is not deserialize it. because jackson is using default constructor for create instance. (or @JsonCreator) and same is true for the parameter module. because not matched parameter name and field name.

If using this module, possible to serialize this class. because this module is created object using objenesis. so create object by-passing Object initialization.

It is inject value through field, setter after force creation. so possible to support more type.

How to use

Add dependency

Maven

<dependency>
    <groupId>software.fitz</groupId>
    <artifactId>jackson-module-force-deserializer</artifactId>
    <version>0.2.0-RELEASE</version>
</dependency>

Gradle

compile group: 'software.fitz', name: 'jackson-module-force-deserializer', version: '0.2.0-RELEASE'

Register module

It is very simple. register module to ObjectMapper class.

ObjectMapper objectMapper = new ObjectMapper()
    .registerModule(new ForceDeserializerModule());

About

Module of jackson for support deserialize to every type as possible

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages