> if I drop on...
Though I am not sure what you mean by "dropping on", but as far as I understood.... ```java SimpleObject *simpleObject *= new SimpleObject(); *simpleObject*.setSingleField("onlyField"); *simpleObject*.setAdditionalProperty("additional", "additional"); *simpleObject*.setAdditionalProperty("remains", "remains"); ``` ...should serialize into `{"singleField":"onlyIfeld"}`. And JSON string `{"onlyField": "someValue", "additional": "anotherValue"}` should deserialize into an instance of `SimpleObject` class with "onlyField" as its singleField and empty map? Try simply removing `@JsonAnySetter` and `@JsonAnyGetter`. Hope it helps, thanks On Monday, August 14, 2023 at 11:59:36 PM UTC+9 Ken Hancock wrote: > > Hi Vince, > > If I'm understanding the implementation of mapper.convertVaue(), I think > it doesn't matter whether it's on serialization or deserialization since > convertValue() does both. > > To illustrate, let's say I have a pojo with one field and the > anySetter/anyGetter: > > @JsonProperty("onlyField") > private String onlyField; > > @JsonAnyGetter > public Map<String, Object> getAdditionalProperties() { > return this.additionalProperties; > } > > @JsonAnySetter > public void setAdditionalProperty(String name, Object value) { > this.additionalProperties.put(name, value); > } > > If I deserialize {"onlyField": "someValue", "additional": "anotherValue"}, > I end up with a pojo with object.getOnlyField() == "someValue") and > object.getAdditionalProperties().get("additional") == "anotherValue") > > Now when I call mapper.convertValue(object, MyPojo.class): > if I drop on serialization, I end up with a serialized object of > {"onlyField": "someValue"} > if I drop on deserialize, I start with a serialized object of > {"onlyField": "someValue", "additional": "anotherValue"} but end up with a > pojo with an empty map in object.getAditionalProperties(). > > If I can do it at either step, I'd love to know how, but either one will > solve my current problem. > > Here's a gist with a sample, which currently fails: > https://gist.github.com/hancockks/02509e5d06b0f1d95b1e3e6c4a23a9f1 > > On Saturday, August 12, 2023 at 8:31:54 AM UTC-4 Joo Hyuk Kim (김주혁) wrote: > >> Hello Ken, >> >> To make things clear, a few questions. >> >> - Meaning of "to strip any additional properties before writing an >> object". Are you looking to exclude `additionalProperties` only during >> serialization, but include in deserialization? >> - Is the primary intent to generate a JSON output that does not >> include `additionalProperties`, or is there another objective? >> - Could you also provide a simple, reproducible example using just >> Jackson and Java? >> >> Thanks, >> >> Joo Hyuk, Kim (Vince) >> On Saturday, August 12, 2023 at 1:31:13 AM UTC+9 Ken Hancock wrote: >> >>> >>> I have a pojo that serializes any additional properties into >>> >>> @JsonAnyGetter >>> public Map<String, Object> getAdditionalProperties() { >>> return this.additionalProperties; >>> } >>> >>> @JsonAnySetter >>> public void setAdditionalProperty(String name, Object value) { >>> this.additionalProperties.put(name, value); >>> } >>> >>> However, I have an odd use case where I want to be able to strip any >>> additional properties before writing an object. I'm fairly sure with all of >>> Jackson's configuration settings that I should be able to configure a >>> mapper such that mapper.convertValue(myPojo, MyPojo.class) should be able >>> to serialize and deserialize back again, dropping the additionalProperties >>> when it serializes? The pojo is deeply nested and auto-generated, so I'd >>> prefer not to hard-code having to just clear additionalProperties at each >>> sub-object. >>> >>> Thanks, >>> >>> Ken >>> >> -- You received this message because you are subscribed to the Google Groups "jackson-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/jackson-user/87386ec9-db4d-4210-8857-14288da795adn%40googlegroups.com.