假设我有这样的JSON:
{
"field":{
"nested":{
"foo":"foo val",
"bar":"bar val",
},
"toignore1":{
},
"toignore2":{
}
}
}我似乎无法正确地解析这一点,而且由于可能是,所以我不知道ingore的所有字段,例如toignore3.,我不想在模型中调用它们。我只需要从整个反应中得到一些价值。如果JSON_STRING表示上面的JSON,为什么我在使用Jerkson解析时不能这样做呢?
case class JsonModel(val field: FieldModel)
case class FieldModel(val nested: NestedModel) // ignoring other stuff here
case class NestedModel(val foo: String, bar: String)
val parsed = parse[JsonModel](JSON_STRING)发布于 2012-11-28 23:59:55
你可以用两种方法中的一种:
case class CaseClassWithIgnoredField(id: Long) {
@JsonIgnore
val uncomfortable = "Bad Touch"
}
@JsonIgnoreProperties(Array("uncomfortable", "unpleasant"))
case class CaseClassWithIgnoredFields(id: Long) {
val uncomfortable = "Bad Touch"
val unpleasant = "The Creeps"
}https://stackoverflow.com/questions/13337495
复制相似问题