tj
2025-06-05 2d549a04870d1315868a7cf19952b64e8071e711
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
 
import java.util.HashMap;
import java.util.Map;
 
@Slf4j
public class Jackson2Test {
 
    @Test
    public void testMap() throws JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper();
        //mapper.setPropertyNamingStrategy(com.fasterxml.jackson.databind.PropertyNamingStrategy.SNAKE_CASE);
        //mapper.configOverride(Map.Entry.class).setFormat(JsonFormat.Value.forShape(JsonFormat.Shape.OBJECT));
        mapper.configOverride(Map.Entry.class).setFormat(JsonFormat.Value.forShape(JsonFormat.Shape.STRING));
        Map<String, Object> res = new HashMap<>();
        res.put("username", "pedro");
        res.put("userAge", 24);
        String s = mapper.writeValueAsString(res);
        log.info(s);
    }
 
    @Test
    public void testCamel() throws JsonProcessingException {
        String str = "userAge";
        String s = StringUtils.camelToUnderline(str);
        log.info(s);
    }
}