Java · Jackson JSON naming
Jackson snake_case ↔ camelCase
Keep Java properties idiomatic camelCase and translate snake_case external JSON names at the serialization boundary.
Use @JsonNaming for one model or DTO
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public class UserProfile {
private String firstName;
private String avatarUrl;
}SnakeCaseStrategy maps properties such as firstName to first_name without annotating every field.
Use ObjectMapper for an application-wide convention
ObjectMapper mapper = new ObjectMapper();
mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
UserProfile profile = mapper.readValue(json, UserProfile.class);
String output = mapper.writeValueAsString(profile);PropertyNamingStrategies.SNAKE_CASE applies the external naming convention during serialization and deserialization.
Use @JsonProperty for explicit exceptions
public class UserProfile {
@JsonProperty("user_id")
private String userId;
@JsonProperty("display_name")
private String displayName;
}Use @JsonProperty when only a few external names are unusual or should bypass the global rule.
Production considerations
- Choose a clear ownership level: class-level strategy, application ObjectMapper, or explicit field mappings.
- Naming strategies affect property names, not arbitrary string values in JSON.
- Duplicate external names that normalize to one property are an API contract problem.
- The examples use Jackson 2.x com.fasterxml.jackson packages; check your major-version migration notes.
Test the JSON boundary online
Use the browser tool to test nested objects, arrays, excluded keys, stop paths, semantic prefixes, collision handling, and a key-only diff before you copy the same convention into an application.
Drop a .json file here or choose one from your device
Files are read only in your browser. Maximum file size: 5 MB.
{
"user_profile": {
"first_name": "Ada",
"created_at": "2026-09-12"
}
}Parsing, file reading, formatting, and key conversion run locally in your browser. JSON input is not sent to a conversion server.