相关文章推荐
捣蛋的眼镜  ·  t sql - How to write ...·  1 年前    · 
完美的板栗  ·  Mysql union all ...·  1 年前    · 
无聊的大熊猫  ·  Deploy Storage Spaces ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I use jackson library and I have @JsonPOJOBuilder class for deserialize JSON. I added @JsonIgnoreProperties for ignore some fields. For example:

@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@SuperBuilder
@JsonDeserialize(builder = SubClass.BuilderImpl.class)
public class SubClass extends MainClass {
    @JsonPOJOBuilder(withPrefix = "")
    @JsonIgnoreProperties({"a1", "a2"})
    static final class BuilderImpl
            extends builder<SubClass, BuilderImpl> {
    public SubClass() {
        super();

I need get throw when json with some of ignored field, such as

objectMapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, true);

How can I do this with annotation or, maybe, exist other variant do this in SubClass?

Thanks a lot.

Do you want to throw an exception when there is any unknown field in json other than ignored fields? – Smile May 14, 2020 at 7:49 @Smile, Yes, i want to throw an exception when there is any unknown fields or ignored fields. – Lyudmila Kuzmicheva May 16, 2020 at 14:55 Did you try @JsonIgnoreProperties(ignoreUnknown = false)? (Though I think this is the default behaviour) – Smile May 16, 2020 at 15:21 @Smile, yes, but it didn't help :( Unknown fields throwed an exception, but ignored fields was without exception. – Lyudmila Kuzmicheva May 17, 2020 at 8:31

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.