Ich habe ein Formular, das Liste der Kunden zurückgeben sollte.
sollte diese Form anders in zwei Fall verhalten:
Ignorieren abwesend Eigenschaft beim Mapping JSON Antwort
- Benutzer startet die Forschung nur "Nachname"
- Benutzer startet die Forschung mit Name und Vorname
In der ersten Verwendung Falls die JSON-Antwort weniger Felder hat als die Antwort im zweiten Fall, muss ich alle diese Felder ignorieren.
Ich habe versucht, mit @JsonInclude(JsonInclude.Include.NON_ABSENT)
, @JsonInclude(JsonInclude.Include.NON_EMPTY)
und @JsonInclude(JsonInclude.Include.NON_NULL)
aber mit jedem und jeder von ihnen der Fehler zurückgegeben wird, ist immer die gleiche:
java.lang.Exception: Could not write content: (was java.lang.NullPointerException) (through reference chain: it.gruppoitas.itasacquire.pojo.Cliente["DATA_NASCITA"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: it.gruppoitas.itasacquire.pojo.Cliente["DATA_NASCITA"])
Dies ist pojo Cliente:
package it.gruppoitas.itasacquire.pojo;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
@JsonInclude(JsonInclude.Include.NON_ABSENT)
public class Cliente {
@JsonProperty("TIPO_PERSONA")
private String tipoPersona;
@JsonProperty("PRO_CLIE")
private String proClie;
@JsonProperty("CODICE_FISCALE")
private String codiceFiscale;
@JsonProperty("DATA_NASCITA")
private String dataNascita;
@JsonProperty("SESSO")
private String sesso;
@JsonProperty("NOME")
private String nome;
@JsonProperty("COGNOME")
private String cognome;
public String getTipoPersona() {
return tipoPersona;
}
public void setTipoPersona(String tipoPersona) {
this.tipoPersona = tipoPersona;
}
public String getProClie() {
return proClie;
}
public void setProClie(String proClie) {
this.proClie = proClie;
}
public String getCodiceFiscale() {
return codiceFiscale;
}
public void setCodiceFiscale(String codiceFiscale) {
this.codiceFiscale = codiceFiscale;
}
public String getDataNascita() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
Date data = null;
try {
data = sdf.parse(dataNascita);
dataNascita = new SimpleDateFormat("dd/MM/yyyy").format(data);
} catch (ParseException e) {
System.err.println(e);
}
return dataNascita;
}
public void setDataNascita(String dataNascita) {
this.dataNascita = dataNascita;
}
public String getSesso() {
return sesso;
}
public void setSesso(String sesso) {
this.sesso = sesso;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getCognome() {
return cognome;
}
public void setCognome(String cognome) {
this.cognome = cognome;
}
@Override
public String toString() {
return "Cliente [tipoPersona=" + tipoPersona + ", proClie=" + proClie + ", codiceFiscale=" + codiceFiscale + ", dataNascita="
+ dataNascita + ", sesso=" + sesso + ", nome=" + nome + ", cognome=" + cognome + "]";
}}
Irgendeine Idee?
EDIT: dies ist ein Beispiel für die json Antwortstruktur in Fall 1
{
"TIPO_PERSONA" : "G",
"PRO_CLIE" : "123456789",
"CODICE_FISCALE" : "123456789",
"PARTITA_IVA" : "123456789",
"SESSO" : "S",
"COGNOME" : "CUSTOMER SRL"
}
Und dies ist ein Beispiel für die json Reaktion in Fall 2:
{
"TIPO_PERSONA" : "F",
"PRO_CLIE" : "123456789",
"CODICE_FISCALE" : "123456789",
"DATA_NASCITA" : "1969-09-07 00:00:00.0",
"SESSO" : "F",
"NOME" : "Foo",
"COGNOME" : "Fie"
}
Wie Sie sehen können, gibt es weniger Felder in Fall 1 und STS geht in den Voll-Panik-Modus ...
können Sie bitte auch ein Beispiel für die Daten, die Sie analysieren möchten, posten? –
versuchen Sie, Ihre Annotation zu ändern: '@JsonInclude (Include.NON_NULL)' oder '@JsonInclude (JsonSerialize.Inclusion.NON_NULL)' – Lucas
diese Annotationen geben mir den gleichen Fehler: "Include/JsonSerialize kann nicht in eine Variable aufgelöst werden" –