По сути, у меня возникли проблемы с анализом Джексоном JSON, возвращенного с сервера RestAPI. Объекты JSON, которые он анализирует, успешно используются в приложении Android, а также в приложении IOS без проблем с сервером RestAPI.
По сути, чтобы отладить проблему, я удалил медиа-плагин Jersey, и jersey просто вернул строку объекта, а затем передал ее в ObjectMapper. Я использую последнюю версию Jackson 2.4.4.
У меня есть специальный десериализатор, который работает с форматом даты, и ошибки, которые я получаю, всегда связаны с этой датой. Необработанный JSON выглядит нормально, но преобразователь объектов Джексона выдает ошибку. Ошибка не всегда находится в одной и той же позиции, но всегда с последней датой проверки. Иногда ошибка говорит о том, что строка пуста, которую она пытается проанализировать, или строка содержит какие-то странные значения.
Вот код, который, мы надеемся, пояснит:
Класс EstatementEntity, у которого возникли проблемы с анализом:
Код: Выделить всё
@JsonIgnoreProperties(ignoreUnknown = true)
public class EstablishmentEntity {
private long id;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
private String establishmentName;
public String getEstablishmentName() {
return establishmentName;
}
public void setEstablishmentName(String establishmentName) {
this.establishmentName = establishmentName;
}
private String address;
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
private String city;
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
private String county;
public String getCounty() {
return county;
}
public void setCounty(String county) {
this.county = county;
}
private String stateOrProvince;
public String getStateOrProvince() {
return stateOrProvince;
}
public void setStateOrProvince(String stateOrProvince) {
this.stateOrProvince = stateOrProvince;
}
private String postalCode;
public String getPostalCode() {
return postalCode;
}
public void setPostalCode(String postalCode) {
this.postalCode = postalCode;
}
private String telephone;
public String getTelephone() {
return telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
private String establishmentType;
public String getEstablishmentType() {
return establishmentType;
}
public void setEstablishmentType(String establishmentType) {
this.establishmentType = establishmentType;
}
@JsonSerialize(using = JsonDateOnlySerializer.class)
@JsonDeserialize(using = JsonDateOnlyDeserializer.class)
private Date lastInspectionDate;
public Date getLastInspectionDate() {
return lastInspectionDate;
}
public void setLastInspectionDate(Date lastInspectionDate) {
this.lastInspectionDate = lastInspectionDate;
}
private String lastInspectionScore;
public String getLastInspectionScore() {
return lastInspectionScore;
}
public void setLastInspectionScore(String lastInspectionScore) {
this.lastInspectionScore = lastInspectionScore;
}
@JsonSerialize(using = JsonDateOnlySerializer.class)
@JsonDeserialize(using = JsonDateOnlyDeserializer.class)
private Date lastInspectionScoreDate;
public Date getLastInspectionScoreDate() {
return lastInspectionScoreDate;
}
public void setLastInspectionScoreDate(Date lastInspectionScoreDate) {
this.lastInspectionScoreDate = lastInspectionScoreDate;
}
private String lastInspectionGrade;
public String getLastInspectionGrade() {
return lastInspectionGrade;
}
public void setLastInspectionGrade(String lastInspectionGrade) {
this.lastInspectionGrade = lastInspectionGrade;
}
@JsonSerialize(using = JsonDateOnlySerializer.class)
@JsonDeserialize(using = JsonDateOnlyDeserializer.class)
private Date lastInspectionGradeDate;
public Date getLastInspectionGradeDate() {
return lastInspectionGradeDate;
}
public void setLastInspectionGradeDate(Date lastInspectionGradeDate) {
this.lastInspectionGradeDate = lastInspectionGradeDate;
}
private String healthDepartment;
public String getHealthDepartment() {
return healthDepartment;
}
public void setHealthDepartment(String healthDepartment) {
this.healthDepartment = healthDepartment;
}
private boolean lastInspectionCritical;
public boolean isLastInspectionCritical() {
return lastInspectionCritical;
}
public void setLastInspectionCritical(boolean lastInspectionCritical) {
this.lastInspectionCritical = lastInspectionCritical;
}
private boolean lastInspectionPriority;
public boolean isLastInspectionPriority() {
return lastInspectionPriority;
}
public void setLastInspectionPriority(boolean lastInspectionPriority) {
this.lastInspectionPriority = lastInspectionPriority;
}
private boolean lastInspectionPriorityFoundation;
public boolean isLastInspectionPriorityFoundation() {
return lastInspectionPriorityFoundation;
}
public void setLastInspectionPriorityFoundation(boolean lastInspectionPriorityFoundation) {
this.lastInspectionPriorityFoundation = lastInspectionPriorityFoundation;
}
private double latitude;
public double getLatitude() {
return latitude;
}
public void setLatitude(double latitude) {
this.latitude = latitude;
}
private double longitude;
public double getLongitude() {
return longitude;
}
public void setLongitude(double longitude) {
this.longitude = longitude;
}
private Timestamp added;
public Timestamp getAdded() {
return added;
}
public void setAdded(Timestamp added) {
this.added = added;
}
private String geocoder;
public String getGeocoder() {
return geocoder;
}
public void setGeocoder(String geocoder) {
this.geocoder = geocoder;
}
private String geocoderVersion;
public String getGeocoderVersion() {
return geocoderVersion;
}
public void setGeocoderVersion(String geocoderVersion) {
this.geocoderVersion = geocoderVersion;
}
private Double hdscoreRankingPercent;
public Double getHdscoreRankingPercent() {
return hdscoreRankingPercent;
}
public void setHdscoreRankingPercent(Double hdscoreRankingPercent) {
this.hdscoreRankingPercent = hdscoreRankingPercent;
}
private String hdscoreProvider;
public String getHdscoreProvider() {
return hdscoreProvider;
}
public void setHdscoreProvider(String hdscoreProvider) {
this.hdscoreProvider = hdscoreProvider;
}
private Double hdscore;
public Double getHdscore() {
return hdscore;
}
public void setHdscore(Double hdscore) {
this.hdscore = hdscore;
}
private String hdscoreVersion;
public String getHdscoreVersion() {
return hdscoreVersion;
}
public void setHdscoreVersion(String hdscoreVersion) {
this.hdscoreVersion = hdscoreVersion;
}
}
Код: Выделить всё
public class JsonDateOnlyDeserializer extends JsonDeserializer {
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
@Override
public Date deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
String dateString = jp.getText();
try {
return dateFormat.parse(dateString);
}
catch (ParseException e) { < b r / > t h r o w n e w R u n t i m e E x c e p t i o n ( e ) ; < b r / > } < b r / > < b r / > } < b r / > } < b r / > < / c o d e > < b r / > < b r / > П р и м е р н е о б р а б о т а н н о г о J S O N ( о б р е з а н и з - з а д л и н ы ) : < / p > < b r / > < b r / > < c o d e > { < b r / > " r e s p o n s e I d " : 1 , < b r / > " r e s u l t s L i m i t e d " : t r u e , < b r / > " t o t a l R e s u l t s " : 4 8 5 6 5 1 , < b r / > " g e o H a s h L e v e l " : 2 , < b r / > " i t e m s " : [ < b r / > { < b r / > " e s t a b l i s h m e n t E n t i t y " : { < b r / > " i d " : 4 6 9 7 1 5 , < b r / > " e s t a b l i s h m e n t N a m e " : " P E N N Y ' S K I T C H E N " , < b r / > " a d d r e s s " : " 8 2 2 W 1 4 t h S t " , < b r / > " c i t y " : " C o f f e y v i l l e " , < b r / > " c o u n t y " : " M o n t g o m e r y " , < b r / > " s t a t e O r P r o v i n c e " : " K S " , < b r / > " p o s t a l C o d e " : " 6 7 3 3 7 - 4 4 0 2 " , < b r / > " t e l e p h o n e " : " 9 1 8 3 3 1 7 3 2 1 " , < b r / > " e s t a b l i s h m e n t T y p e " : n u l l , < b r / > " l a s t I n s p e c t i o n S c o r e " : n u l l , < b r / > " l a s t I n s p e c t i o n G r a d e " : n u l l , < b r / > " h e a l t h D e p a r t m e n t " : " S t a t e o f K a n s a s " , < b r / > " l a s t I n s p e c t i o n C r i t i c a l " : f a l s e , < b r / > " l a s t I n s p e c t i o n P r i o r i t y " : f a l s e , < b r / > " l a s t I n s p e c t i o n P r i o r i t y F o u n d a t i o n " : f a l s e , < b r / > " l a t i t u d e " : 3 7 . 0 2 8 7 8 , < b r / > " l o n g i t u d e " : - 9 5 . 6 2 5 3 7 4 , < b r / > " a d d e d " : 1 4 0 9 0 1 6 4 3 5 0 0 0 , < b r / > " g e o c o d e r " : " c o m . h d s c o r e s . i n s p e c t i o n . s o u r c e . g e o c o d i n g . M a p Q u e s t L i c e n s e d G e o c o d e r " , < b r / > " g e o c o d e r V e r s i o n " : " 1 . 1 2 " , < b r / > " h d s c o r e R a n k i n g P e r c e n t " : 0 . 3 0 1 8 2 3 6 7 5 , < b r / > " h d s c o r e P r o v i d e r " : " c o m . h d s c o r e s . i n s p e c t i o n . h d s c o r e . V i o l a t i o n s H D S c o r e P r o v i d e r " , < b r / > " h d s c o r e " : 4 . 3 7 3 9 2 4 4 9 7 6 3 1 4 3 6 , < b r / > " h d s c o r e V e r s i o n " : " 1 . 0 4 " , < b r / > " l a s t I n s p e c t i o n D a t e " : " 2 0 1 3 - 1 0 - 1 7 " , < b r / > " l a s t I n s p e c t i o n S c o r e D a t e " : n u l l , < b r / > " l a s t I n s p e c t i o n G r a d e D a t e " : n u l l < b r / > } , < b r / > " p r e f e r r e d L e v e l " : 0 , < b r / > " l o g o U r l " : n u l l , < b r / > " r e s u l t s T o p " : f a l s e , < b r / > " r e s u l t s B o t t o m " : f a l s e , < b r / > " f e a t u r e d " : f a l s e , < b r / > " r e p o r t s V i o l a t i o n s " : t r u e , < b r / > " d i s p l a y N a m e " : " P E N N Y ' S K I T C H E N " < b r / > } , < b r / > { < b r / > " e s t a b l i s h m e n t E n t i t y " : { < b r / > " i d " : 2 8 1 2 5 3 , < b r / > " e s t a b l i s h m e n t N a m e " : " C O F F E Y V I L L E L I V E S T O C K M A R K E T " , < b r / > " a d d r e s s " : " 8 2 2 W 1 4 t h S t " , < b r / > " c i t y " : " C o f f e y v i l l e " , < b r / > " c o u n t y " : " M o n t g o m e r y " , < b r / > " s t a t e O r P r o v i n c e " : " K S " , < b r / > " p o s t a l C o d e " : " 6 7 3 3 7 - 4 4 0 2 " , < b r / > " t e l e p h o n e " : " 6 2 0 2 5 1 5 4 6 0 " , < b r / > " e s t a b l i s h m e n t T y p e " : n u l l , < b r / > " l a s t I n s p e c t i o n S c o r e " : n u l l , < b r / > " l a s t I n s p e c t i o n G r a d e " : n u l l , < b r / > " h e a l t h D e p a r t m e n t " : " S t a t e o f K a n s a s " , < b r / > " l a s t I n s p e c t i o n C r i t i c a l " : t r u e , < b r / > " l a s t I n s p e c t i o n P r i o r i t y " : f a l s e , < b r / > " l a s t I n s p e c t i o n P r i o r i t y F o u n d a t i o n " : f a l s e , < b r / > " l a t i t u d e " : 3 7 . 0 2 8 7 8 , < b r / > " l o n g i t u d e " : - 9 5 . 6 2 5 3 7 4 , < b r / > " a d d e d " : 1 4 0 5 6 2 3 4 9 6 0 0 0 , < b r / > " g e o c o d e r " : " c o m . h d s c o r e s . i n s p e c t i o n . s o u r c e . g e o c o d i n g . M a p Q u e s t L i c e n s e d G e o c o d e r " , < b r / > " g e o c o d e r V e r s i o n " : " 1 . 1 2 " , < b r / > " h d s c o r e R a n k i n g P e r c e n t " : 0 . 1 3 3 0 5 2 7 6 7 , < b r / > " h d s c o r e P r o v i d e r " : " c o m . h d s c o r e s . i n s p e c t i o n . h d s c o r e . V i o l a t i o n s H D S c o r e P r o v i d e r " , < b r / > " h d s c o r e " : 6 . 5 , < b r / > " h d s c o r e V e r s i o n " : " 1 . 0 4 " , < b r / > " l a s t I n s p e c t i o n D a t e " : " 2 0 1 1 - 0 6 - 2 3 " , < b r / > " l a s t I n s p e c t i o n S c o r e D a t e " : n u l l , < b r / > " l a s t I n s p e c t i o n G r a d e D a t e " : n u l l < b r / > } , < b r / > " p r e f e r r e d L e v e l " : 0 , < b r / > " l o g o U r l " : n u l l , < b r / > " r e s u l t s T o p " : f a l s e , < b r / > " r e s u l t s B o t t o m " : f a l s e , < b r / > " f e a t u r e d " : f a l s e , < b r / > " r e p o r t s V i o l a t i o n s " : t r u e , < b r / > " d i s p l a y N a m e " : " C O F F E Y V I L L E L I V E S T O C K M A R K E T " < b r / > } , < b r / > { < b r / > " e s t a b l i s h m e n t E n t i t y " : { < b r / > " i d " : 3 6 8 1 6 6 , < b r / > " e s t a b l i s h m e n t N a m e " : " T R O P I C A L S N O " , < b r / > " a d d r e s s " : " 8 2 3 E 1 1 t h S t " , < b r / > " c i t y " : " C o f f e y v i l l e " , < b r / > " c o u n t y " : " M o n t g o m e r y " , < b r / > " s t a t e O r P r o v i n c e " : " K S " , < b r / > " p o s t a l C o d e " : " 6 7 3 3 7 - 6 6 0 3 " , < b r / > " t e l e p h o n e " : " 6 2 0 3 3 0 3 2 9 6 " , < b r / > " e s t a b l i s h m e n t T y p e " : n u l l , < b r / > " l a s t I n s p e c t i o n S c o r e " : n u l l , < b r / > " l a s t I n s p e c t i o n G r a d e " : n u l l , < b r / > " h e a l t h D e p a r t m e n t " : " S t a t e o f K a n s a s " , < b r / > " l a s t I n s p e c t i o n C r i t i c a l " : f a l s e , < b r / > " l a s t I n s p e c t i o n P r i o r i t y " : f a l s e , < b r / > " l a s t I n s p e c t i o n P r i o r i t y F o u n d a t i o n " : f a l s e , < b r / > " l a t i t u d e " : 3 7 . 0 3 2 9 3 7 , < b r / > " l o n g i t u d e " : - 9 5 . 6 0 2 0 5 7 , < b r / > " a d d e d " : 1 4 0 6 3 6 7 3 0 9 0 0 0 , < b r / > " g e o c o d e r " : " c o m . h d s c o r e s . i n s p e c t i o n . s o u r c e . g e o c o d i n g . M a p Q u e s t L i c e n s e d G e o c o d e r " , < b r / > " g e o c o d e r V e r s i o n " : " 1 . 1 2 " , < b r / > " h d s c o r e R a n k i n g P e r c e n t " : 0 . 4 4 9 2 2 8 4 4 5 , < b r / > " h d s c o r e P r o v i d e r " : " c o m . h d s c o r e s . i n s p e c t i o n . h d s c o r e . V i o l a t i o n s H D S c o r e P r o v i d e r " , < b r / > " h d s c o r e " : 3 . 3 1 7 2 0 1 7 9 2 8 8 6 3 2 7 5 , < b r / > " h d s c o r e V e r s i o n " : " 1 . 0 4 " , < b r / > " l a s t I n s p e c t i o n D a t e " : " 2 0 1 3 - 0 4 - 0 4 " , < b r / > " l a s t I n s p e c t i o n S c o r e D a t e " : n u l l , < b r / > " l a s t I n s p e c t i o n G r a d e D a t e " : n u l l < b r / > } , < b r / > " p r e f e r r e d L e v e l " : 1 , < b r / > " l o g o U r l " : n u l l , < b r / > " r e s u l t s T o p " : f a l s e , < b r / > " r e s u l t s B o t t o m " : f a l s e , < b r / > " f e a t u r e d " : f a l s e , < b r / > " r e p o r t s V i o l a t i o n s " : t r u e , < b r / > " d i s p l a y N a m e " : " T R O P I C A L SNO"
},
{
"establishmentEntity":{
"id":494794,
"establishmentName":"SIR VON II",
"address":"806 E 11th St",
"city":"Coffeyville",
"county":"Montgomery",
"stateOrProvince":"KS",
"postalCode":"67337-6604",
"telephone":"6206886321",
"establishmentType":null,
"lastInspectionScore":null,
"lastInspectionGrade":null,
"healthDepartment":"State of Kansas",
"lastInspectionCritical":true,
"lastInspectionPriority":false,
"lastInspectionPriorityFoundation":false,
"latitude":37.032902,
"longitude":-95.604437,
"added":1410044780000,
"geocoder":"com.hdscores.inspection.source.geocoding.MapQuestLicensedGeocoder",
"geocoderVersion":"1.12",
"hdscoreRankingPercent":0.195856264,
"hdscoreProvider":"com.hdscores.inspection.hdscore.ViolationsHDScoreProvider",
"hdscore":5.5,
"hdscoreVersion":"1.04",
"lastInspectionDate":"2012-07-30",
"lastInspectionScoreDate":null,
"lastInspectionGradeDate":null
},
"preferredLevel":0,
"logoUrl":null,
"resultsTop":false,
"resultsBottom":false,
"featured":false,
"reportsViolations":true,
"displayName":"SIR VON II"
},
{
"establishmentEntity":{
"id":377960,
"establishmentName":"DAYS INN",
"address":"820 E 11th St",
"city":"Coffeyville",
"county":"Montgomery",
"stateOrProvince":"KS",
"postalCode":"67337-6604",
"telephone":"6202510002",
"establishmentType":null,
"lastInspectionScore":null,
"lastInspectionGrade":null,
"healthDepartment":"State of Kansas",
"lastInspectionCritical":false,
"lastInspectionPriority":false,
"lastInspectionPriorityFoundation":false,
"latitude":37.0329,
"longitude":-95.60475,
"added":1406692555000,
"geocoder":"com.hdscores.inspection.source.geocoding.MapQuestLicensedGeocoder",
"geocoderVersion":"1.12",
"hdscoreRankingPercent":0.6747599,
"hdscoreProvider":"com.hdscores.inspection.hdscore.ViolationsHDScoreProvider",
"hdscore":2.0,
"hdscoreVersion":"1.04",
"lastInspectionDate":"2013-12-24",
"lastInspectionScoreDate":null,
"lastInspectionGradeDate":null
},
"preferredLevel":1,
"logoUrl":null,
"resultsTop":false,
"resultsBottom":false,
"featured":false,
"reportsViolations":true,
"displayName":"DAYS INN"
},
{
"establishmentEntity":{
"id":119641,
"establishmentName":"SIRLOIN STOCKADE",
"address":"104 W 11th St",
"city":"Coffeyville",
"county":"Montgomery",
"stateOrProvince":"KS",
"postalCode":"67337-5902",
"telephone":"6202518156",
"establishmentType":null,
"lastInspectionScore":null,
"lastInspectionGrade":null,
"healthDepartment":"State of Kansas",
"lastInspectionCritical":false,
"lastInspectionPriority":false,
"lastInspectionPriorityFoundation":false,
"latitude":37.03298,
"longitude":-95.615787,
"added":1400599518000,
"geocoder":"com.hdscores.inspection.source.geocoding.MapQuestGeocoder",
"geocoderVersion":"1.00",
"hdscoreRankingPercent":0.147512679,
"hdscoreProvider":"com.hdscores.inspection.hdscore.ViolationsHDScoreProvider",
"hdscore":6.209693418399466,
"hdscoreVersion":"1.04",
"lastInspectionDate":"2014-03-07",
"lastInspectionScoreDate":null,
"lastInspectionGradeDate":null
},
"preferredLevel":0,
"logoUrl":null,
"resultsTop":false,
"resultsBottom":false,
"featured":false,
"reportsViolations":true,
"displayName":"SIRLOIN STOCKADE"
},
Код: Выделить всё
java.lang.RuntimeException: com.fasterxml.jackson.databind.JsonMappingException: multiple points (through reference chain: com.hdscores.consumer.service.client.SearchResponse["items"]->java.util.ArrayList[0]->com.hdscores.consumer.service.client.Establishment["establishmentEntity"]->com.hdscores.consumer.service.client.EstablishmentEntity["lastInspectionDate"])
(Removed intermediate errors)
Caused by: java.lang.NumberFormatException: multiple points
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1101)
at java.lang.Double.parseDouble(Double.java:540)
at java.text.DigitList.getDouble(DigitList.java:168)
at java.text.DecimalFormat.parse(DecimalFormat.java:1321)
at java.text.SimpleDateFormat.subParse(SimpleDateFormat.java:2088)
at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1455)
at java.text.DateFormat.parse(DateFormat.java:355)
at com.hdscores.consumer.service.client.JsonDateOnlyDeserializer.deserialize(JsonDateOnlyDeserializer.java:23)
at com.hdscores.consumer.service.client.JsonDateOnlyDeserializer.deserialize(JsonDateOnlyDeserializer.java:16)
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:538)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:99)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:238)
... 51 more
Код: Выделить всё
Caused by: java.lang.NumberFormatException: For input string: "5E51"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Long.parseLong(Long.java:441)
at java.lang.Long.parseLong(Long.java:483)
at java.text.DigitList.getLong(DigitList.java:194)
at java.text.DecimalFormat.parse(DecimalFormat.java:1316)
at java.text.SimpleDateFormat.subParse(SimpleDateFormat.java:1793)
at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1455)
at java.text.DateFormat.parse(DateFormat.java:355)
at com.hdscores.consumer.service.client.JsonDateOnlyDeserializer.deserialize(JsonDateOnlyDeserializer.java:23)
at com.hdscores.consumer.service.client.JsonDateOnlyDeserializer.deserialize(JsonDateOnlyDeserializer.java:16)
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:538)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:99)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:238)
Любое помогите, буду признателен....
Подробнее здесь: https://stackoverflow.com/questions/275 ... sing-issue
Мобильная версия