forked from owlike/genson
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for owlike#123 - Add support for preservation of unknown properties
- Loading branch information
Showing
6 changed files
with
282 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
genson/src/main/java/com/owlike/genson/reflect/UnknownPropertyHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.owlike.genson.reflect; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* An interface that defines callbacks that will be called when an | ||
* unknown properties are encountered during deserialization, as well | ||
* as to check if there are any unknown properties that should be | ||
* written out during serialization. | ||
* <p> | ||
* The main purpose of this interface is to support schema evolution | ||
* of objects that use JSON as a long term storage format, without | ||
* loss of unknown properties across clients and severs using different | ||
* versions of Java classes. | ||
* | ||
* @author Aleksandar Seovic 2018.05.09 | ||
*/ | ||
public interface UnknownPropertyHandler { | ||
/** | ||
* Called whenever a property is encountered in a JSON document | ||
* that doesn't have a corresponding {@link PropertyMutator}. | ||
* <p> | ||
* Typically, the implementation of this interface concerned | ||
* with schema evolution will handle this event by storing | ||
* property value somewhere so it can be returned by the | ||
* {@link #getUnknownProperties} method. | ||
* | ||
* @param target the object we are deserializing JSON into | ||
* @param propName the name of the unknown property | ||
* @param propValue the value of the unknown property | ||
*/ | ||
void onUnknownProperty(Object target, String propName, Object propValue); | ||
|
||
/** | ||
* Return a map of unknown properties encountered during | ||
* deserialization, keyed by property name. | ||
* | ||
* @param source the object we are serializing into JSON | ||
* | ||
* @return a map of unknown properties | ||
*/ | ||
Map<String, Object> getUnknownProperties(Object source); | ||
} |
Oops, something went wrong.