Object mapper и Json array

SQLite, Preferences, файлы, SD, Content Provider, XML, JSON
Ответить
Merovengian
Сообщения: 1
Зарегистрирован: 15 ноя 2016, 13:28

Object mapper и Json array

Сообщение Merovengian » 15 ноя 2016, 13:35

Добрый день, помогите, пожалуйста, советом
Имеется json
{"cities":[{"name":"Pyongyang","id":"1871859","country":"North Korea","countryId":"1873107"},{"name":"Pune","id":"1259229","country":"India","countryId":"1269750"},{"name":"Paris","id":"2988507","country":"France","countryId":"3017382"},{"name":"Pretoria","id":"964137","country":"South Africa","countryId":"953987"},{"name":"Patna","id":"1260086","country":"India","countryId":"1269750"},{"name":"Puebla","id":"3521081","country":"Mexico","countryId":"3996063"}]}

Имеется objectmapper

ObjectMapper objectMapper = new ObjectMapper();
objectMapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true); objectMapper.setVisibilityChecker(objectMapper.getSerializationConfig().getDefaultVisibilityChecker()
.withFieldVisibility(JsonAutoDetect.Visibility.ANY)
.withGetterVisibility(JsonAutoDetect.Visibility.NONE)
.withSetterVisibility(JsonAutoDetect.Visibility.DEFAULT)
.withIsGetterVisibility(JsonAutoDetect.Visibility.NONE)
.withCreatorVisibility(JsonAutoDetect.Visibility.NONE));
return objectMapper;

И сам класс город

import android.os.Parcelable;
import java.util.HashMap;
import java.util.Map;
import android.os.Parcel;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonRootName;
@JsonRootName(value = "cities")
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"name",
"id",
"country",
"countryId"
})
public class City implements Parcelable{

@JsonProperty("name")
private String name;
@JsonProperty("id")
private String id;
@JsonProperty("country")
private String country;
@JsonProperty("countryId")
private String countryId;
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
public City() {
}
/**
*
* @return
* The name
*/
@JsonProperty("name")
public String getName() {
return name;
}

/**
*
* @param name
* The name
*/
@JsonProperty("name")
public void setName(String name) {
this.name = name;
}

/**
*
* @return
* The id
*/
@JsonProperty("id")
public String getId() {
return id;
}

/**
*
* @param id
* The id
*/
@JsonProperty("id")
public void setId(String id) {
this.id = id;
}

/**
*
* @return
* The country
*/
@JsonProperty("country")
public String getCountry() {
return country;
}

/**
*
* @param country
* The country
*/
@JsonProperty("country")
public void setCountry(String country) {
this.country = country;
}

/**
*
* @return
* The countryId
*/
@JsonProperty("countryId")
public String getCountryId() {
return countryId;
}

/**
*
* @param countryId
* The countryId
*/
@JsonProperty("countryId")
public void setCountryId(String countryId) {
this.countryId = countryId;
}

@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}

@JsonAnySetter
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.id);
dest.writeString(this.name);
dest.writeString(this.country);
dest.writeString(this.countryId);
}

protected City(Parcel in) {
this.name = in.readString();
this.id = in.readString();
this.country = in.readString();
this.countryId = in.readString();
}

public static final Parcelable.Creator<City> CREATOR = new Parcelable.Creator<City>() {
@Override
public City createFromParcel(Parcel source) {
return new City(source);
}

@Override
public City[] newArray(int size) {
return new City[size];
}
};


Прошу, скажите, почему он не парсит как надо? и если не сложно, поскажите, куда мне копать, или что я делаю неправильно?

Ответить