Open tosslife opened 6 years ago
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.parser.ParserConfig;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.PropertyNamingStrategy;
public class Main {
public static void main(String[] args) {
// Set property naming strategy for serialization
SerializeConfig.getGlobalInstance().propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
// Set property naming strategy for deserialization
ParserConfig.getGlobalInstance().propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
// Your JSON data
String jsonData = "{\"person_id\": 123, \"name\": \"John Doe\"}";
// Deserialize JSON into your model class
Person person = JSON.parseObject(jsonData, Person.class);
// Print the deserialized object
System.out.println(person.getPersonId()); // This should print the value of person_id
System.out.println(person.getName()); // This should print the value of name
}
// Your model class
static class Person {
private int personId;
private String name;
// Getters and setters
public int getPersonId() {
return personId;
}
public void setPersonId(int personId) {
this.personId = personId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
1.2.47版本 jdk1.8 feign请求结果反序列化时候 json格式是中 personid 转换成 model 驼峰 personId 则结果丢失 但是 json中 name 对应model中 name 这种没有 对应非驼峰的 不会丢失
已设置 但仍旧是无效