Skip to content

Annotation based polymorphic deserialization wrapped around Gson

License

Notifications You must be signed in to change notification settings

kardolus/polymorphic-object-mapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Polymorphic ObjectMapper

This library was originally created to limit the number of nulls that usually float around in a Java program. It enables you to deserialize a Json string using interfaces rather than classes.

You can either use a set of objects (with a common ancestor) to get its concrete implementor using fromJson(String json, Set objects) or you can annotate your interface with @PolymorphicDeserialize and use the method fromJson(String json, Class<T> interface) instead.

The annotation @PolymorphicDeserialize takes an optional argument classes that can be used to provide a array of candidates, and an optional argument called basePackage which is used to specify the basePackage of your component scan. The classes method allows you to limit the implementors that will be considered for deserialization; like a filter. Omitting the classes and basePackage arguments will cause a scan of all the classes that are in the same package as the interface itself, including sub packages. If the interface is not in the same package structure as the candidate classes you have to explicitly specify them or you will have to use the basePackage annotation to scan the specified package for implementors. Component scans are recursive.

Roadmap:

  • Allow null values through method or field level annotation
  • Return "best match" rather than first match. Best match has the most matching fields of all scanned classes
  • @PolymorphicDeserialize annotation should disable the standard Jackson deserialization used by the Spring Framework
  • Squash commits
  • Publish project to maven central

Resources:

About

Annotation based polymorphic deserialization wrapped around Gson

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages