Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

139
Views
Jackson + Autovalue Builder bean validation

I have a the following Event DTO class:

@AutoValue
@JsonDeserialize(builder = AutoValue_Event.Builder.class)
@JsonIgnoreProperties(ignoreUnknown = true)
public abstract class Event {

    public static Event.Builder builder() {
        return new AutoValue_Event.Builder();
    }

    public abstract UUID id();

    @NotNull
    public abstract Type type();

    @NotNull
    @JsonSerialize(using = LocalDateSerializer.class)
    @JsonDeserialize(using = LocalDateDeserializer.class)
    public abstract LocalDate date();

    @AutoValue.Builder
    public abstract static class Builder {

        @JsonProperty("id")
        public abstract Builder id(UUID id);

        @JsonProperty("type")
        public abstract Builder type(Type type);

        @JsonProperty("date")
        public abstract Builder date(LocalDate date);

   }
}

The validation works well for type and date attributes and Jackson throws a JsonMappingException as expected when the payload is not correct. Unfortunately, the returned error message is a text/plain like: JsonMappingException: Can not construct instance of project.dto.AutoValue_Event$Builder, problem: Missing required properties: type.

Is there a way to handle those validation errors and return a explicit json error object?

I found this post to catch the exception and return an explicit json but I can't map a custom error message on which field the deserialization failed (I don't want to parse the message exception to know which field is incorrect). Any idea?

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!