Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
ignoring unknown properties on de-serializing process with JsonArrayF…
…ormat
  • Loading branch information
marenzo committed Jul 5, 2016
commit 085e87d35843c8a522a687606e5e4c27d4469e8f
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.introspect.Annotated;
import com.fasterxml.jackson.databind.introspect.AnnotatedClass;
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;

import static com.fasterxml.jackson.annotation.JsonFormat.Shape.ARRAY;
Expand All @@ -17,6 +18,10 @@ public class JsonArrayFormat extends JacksonAnnotationIntrospector
{
private static final JsonFormat.Value ARRAY_FORMAT = new JsonFormat.Value().withShape(ARRAY);

/**
* Defines array format for serialized entities with ObjectMapper, without actually
* including the schema
*/
@Override
public JsonFormat.Value findFormat(Annotated ann)
{
Expand All @@ -28,4 +33,21 @@ public JsonFormat.Value findFormat(Annotated ann)

return ARRAY_FORMAT;
}

/**
* Defines that unknown properties will be ignored, and won't fail the un-marshalling process.
* Happens in case of de-serialization of a payload that contains more properties than the actual
* value type
*/
@Override
public Boolean findIgnoreUnknownProperties(AnnotatedClass ac)
{
// If the entity contains JsonIgnoreProperties annotation, give it higher priority.
final Boolean precedenceIgnoreUnknownProperties = super.findIgnoreUnknownProperties(ac);
if (precedenceIgnoreUnknownProperties != null) {
return precedenceIgnoreUnknownProperties;
}

return true;
}
}