Skip to content

Commit c9fd454

Browse files
authored
Merge pull request #373 from marenzo/develop
Ignoring unknown properties on de-serializing process
2 parents fb6a213 + 085e87d commit c9fd454

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

msgpack-jackson/src/main/java/org/msgpack/jackson/dataformat/JsonArrayFormat.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.fasterxml.jackson.annotation.JsonFormat;
44
import com.fasterxml.jackson.databind.introspect.Annotated;
5+
import com.fasterxml.jackson.databind.introspect.AnnotatedClass;
56
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
67

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

21+
/**
22+
* Defines array format for serialized entities with ObjectMapper, without actually
23+
* including the schema
24+
*/
2025
@Override
2126
public JsonFormat.Value findFormat(Annotated ann)
2227
{
@@ -28,4 +33,21 @@ public JsonFormat.Value findFormat(Annotated ann)
2833

2934
return ARRAY_FORMAT;
3035
}
36+
37+
/**
38+
* Defines that unknown properties will be ignored, and won't fail the un-marshalling process.
39+
* Happens in case of de-serialization of a payload that contains more properties than the actual
40+
* value type
41+
*/
42+
@Override
43+
public Boolean findIgnoreUnknownProperties(AnnotatedClass ac)
44+
{
45+
// If the entity contains JsonIgnoreProperties annotation, give it higher priority.
46+
final Boolean precedenceIgnoreUnknownProperties = super.findIgnoreUnknownProperties(ac);
47+
if (precedenceIgnoreUnknownProperties != null) {
48+
return precedenceIgnoreUnknownProperties;
49+
}
50+
51+
return true;
52+
}
3153
}

0 commit comments

Comments
 (0)