Created
December 4, 2018 00:04
-
-
Save zacscoding/c52957e37a82be7cba525ab5da14bc7f to your computer and use it in GitHub Desktop.
ObjectMapper naming strategy test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.fasterxml.jackson.databind.ObjectMapper; | |
import com.fasterxml.jackson.databind.PropertyNamingStrategy; | |
import lombok.AllArgsConstructor; | |
import lombok.Getter; | |
import lombok.Setter; | |
import org.junit.Test; | |
/** | |
* @author zacconding | |
* @Date 2018-12-04 | |
* @GitHub : https://github.com/zacscoding | |
*/ | |
public class ObjectMapperTest { | |
@Test | |
public void objectMapperNamingStrategy() throws Exception { | |
PropertyNamingStrategy[] strategies = new PropertyNamingStrategy[] { | |
PropertyNamingStrategy.LOWER_CASE | |
, PropertyNamingStrategy.SNAKE_CASE | |
, PropertyNamingStrategy.KEBAB_CASE | |
, PropertyNamingStrategy.LOWER_CAMEL_CASE | |
, PropertyNamingStrategy.UPPER_CAMEL_CASE | |
}; | |
for (PropertyNamingStrategy strategy : strategies) { | |
System.out.print(">> Test " + strategy.getClass().getSimpleName() + " : "); | |
ObjectMapper mapper = new ObjectMapper(); | |
mapper.setPropertyNamingStrategy(strategy); | |
TempClass inst = new TempClass("hivava", "hivavava"); | |
System.out.println("\t" + mapper.writeValueAsString(inst)); | |
} | |
/* | |
output | |
>> Test LowerCaseStrategy : {"testname":"hivava","test_value":"hivavava"} | |
>> Test SnakeCaseStrategy : {"test_name":"hivava","test_value":"hivavava"} | |
>> Test KebabCaseStrategy : {"test-name":"hivava","test_value":"hivavava"} | |
>> Test PropertyNamingStrategy : {"testName":"hivava","test_value":"hivavava"} | |
>> Test UpperCamelCaseStrategy : {"TestName":"hivava","Test_value":"hivavava"} | |
*/ | |
} | |
@Getter | |
@Setter | |
@AllArgsConstructor | |
public static class TempClass { | |
private String testName; | |
private String test_value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment