Open kai8406 opened 5 days ago
jackson supports to deserialize objects in case insensitive way. Maybe this is the simplest way.
We can configure the ObjectMapper inside the org.bithon.agent.configuration.Binder
.
Here's the sample code
//
// Illustration of deserialization from uppercase 'Age' to lower case property 'age'
//
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
public class Main {
public static void main(String[] args) throws Exception {
ObjectMapper mapper = new ObjectMapper();
// Enable case-insensitive property matching
mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
String json = "{\"name\": \"John\", \"Age\": 30}";
Person person = mapper.readValue(json, Person.class);
System.out.println(person);
}
}
class Person {
private String name;
private int age;
// getters and setters
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public String toString() {
return "Person{name='" + name + "', age=" + age + '}';
}
}
//
// Illustration of same properties in different cases
//
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
public class Main {
public static void main(String[] args) throws Exception {
ObjectMapper mapper = new ObjectMapper();
// Enable case-insensitive property matching
mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
String json = "{\"name\": \"John\", \"Name\": \"Doe\"}";
Person person = mapper.readValue(json, Person.class);
System.out.println(person);
}
}
class Person {
private String name;
// getters and setters
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "Person{name='" + name + "'}";
}
}
Use uppercase letters for environment variable naming.
808