0

I would like to avoid that my REST POST Service (JAX-RS in Spring) returns 400 - Bad Request if I call that service with new fields that it is not able to unmarshal.

Let's do an example:

I have this input request java class:

public class PosizioneDto implements java.io.Serializable {

    private static final long serialVersionUID = 1L;

    private Double controvalore;
    private Double quantita;
    private Double prezzo;
    private ContrattoDto contratto;
    private String progressivoMiFid;
    private String codiceProdotto;
    private String ageC;
    private String prodCPadreMifid;
    private String prodCFiglio1Mifid;
    private String prodCFiglio2Mifid;
    private String tipProd;
}

if in the input JSON request there were another field (e.g. "_newProperty") I would like that parser wouldn't go in error, but simply wouldn't unmarshal that property.

Is this possible to do? Should I use some ExceptionMapper?

MarcoSuma
  • 59
  • 10

1 Answers1

3

If you are using Jackson parser, then use @JsonIgnoreProperties(ignoreUnknown = true) annotation on your POJO class.

You can refer to Ignoring new fields on JSON objects using Jackson

Vasil Lukach
  • 3,658
  • 3
  • 31
  • 40
Rolson Quadras
  • 446
  • 3
  • 8