๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๋ฐ˜์‘ํ˜•

json4

[JAVA] VO๋ฅผ JSON ๋ฐ์ดํ„ฐ๋กœ ๋ณ€ํ™˜ (java class to json, vo to json) ๋จผ์ € ์•„๋ž˜ ํฌ์ŠคํŒ…์„ ๋ณด๊ณ  ํ•„์š”ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ถ”๊ฐ€ํ•˜์ž! [JAVA] JSON ๋ฐ์ดํ„ฐ๋ฅผ VO๋กœ ํŒŒ์‹ฑ, ๋ณ€ํ™˜ํ•˜๋Š” ๋ฐฉ๋ฒ• (json to java class) ๋จผ์ € jackson-databind ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ถ”๊ฐ€ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค! spring boot์˜ ๊ฒฝ์šฐ 'spring-boot-starter-web'์— ํฌํ•จ๋˜์–ด ์žˆ์Œ maven com.fasterxml.jackson.core jackson-databind 2.13.0 gradle // https://mvnrepos.. ynzu-dev.tistory.com vo ์˜ˆ์‹œ public class TestVo { @JsonProperty("user-name") private String userName; @JsonProperty("user-id") private Stri.. 2021. 12. 9.
[JAVA] JSON to VO : JSON์˜ key์™€ vo(java class)์˜ ๋ณ€์ˆ˜๋ช…์ด ๋‹ค๋ฅผ ๊ฒฝ์šฐ ์•ž ํฌ์ŠคํŒ…์—์„œ json ๋ฐ์ดํ„ฐ๋ฅผ vo๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ณด์•˜๊ณ , ์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„  json์˜ key์™€ vo์˜ ๋ณ€์ˆ˜๋ช…์ด ๋‹ค๋ฅผ ๊ฒฝ์šฐ ํ•ด๊ฒฐ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด๊ฒ ๋‹ค. json์˜ key์™€ vo์— ์„ ์–ธ๋œ ๋ณ€์ˆ˜๋ช…์ด ๋‹ค๋ฅผ ๊ฒฝ์šฐ ๋ณ€ํ™˜์‹œ key์˜ ์ด๋ฆ„์„ ๋ณ€๊ฒฝํ•˜์—ฌ ํŒŒ์‹ฑํ•˜๋ ค๋ฉด @JsonProperty์„ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค. json data ์˜ˆ์‹œ {"user-name":"name01", "user-id":"id01"} vo ์˜ˆ์‹œ public class TestVo { @JsonProperty("user-name") private String userName; @JsonProperty("user-id") private String userId; } ์ด๋ ‡๊ฒŒ vo์˜ ๋ณ€์ˆ˜๋ช…์— JsonProperty ์–ด๋…ธํ…Œ์ด์…˜๊ณผ ํ•จ๊ป˜ ๋งคํ•‘ํ•  json d.. 2021. 12. 9.
[JAVA] JSON ๊ฐ์ฒด VO ๋ณ€ํ™˜ ์—๋Ÿฌ : org.codehaus.jackson.map.exc.UnrecognizedPropertyException json ๋ฐ์ดํ„ฐ๋ฅผ vo๋กœ ๋ณ€ํ™˜ํ•  ๋•Œ ํ•ด๋‹น ํด๋ž˜์Šค์— ์„ ์–ธ๋˜์ง€ ์•Š์€ ๋ณ€์ˆ˜(ํ”„๋กœํผํ‹ฐ)๊ฐ€ json์— ์žˆ์œผ๋ฉด ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค. org.codehaus.jackson.map.exc.UnrecognizedPropertyException ํ•ด๋‹น ํ”„๋กœํผํ‹ฐ๋ฅผ ๋ฌด์‹œํ•˜๊ณ ์ž ํ•˜๋Š” ๊ฒฝ์šฐ @JsonIgnoreProperties(ignoreUnknown = true)๋ฅผ ์„ ์–ธํ•˜๋ฉด ๋œ๋‹ค! @JsonIgnoreProperties(ignoreUnknown = true) public class TestVo { private String userName; private String userId; } json ๋ฐ์ดํ„ฐ๊ฐ€ ์•„๋ž˜์™€ ๊ฐ™์ด ๋“ค์–ด์™€๋„ ์ด์ œ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜์ง€ ์•Š๋Š”๋‹ค. {"user-name":"name01", "user-id":"id01", "u.. 2021. 12. 9.
[JAVA] JSON ๋ฐ์ดํ„ฐ๋ฅผ VO๋กœ ํŒŒ์‹ฑ, ๋ณ€ํ™˜ํ•˜๋Š” ๋ฐฉ๋ฒ• (json to java class) ๋จผ์ € jackson-databind ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ถ”๊ฐ€ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค! spring boot์˜ ๊ฒฝ์šฐ 'spring-boot-starter-web'์— ํฌํ•จ๋˜์–ด ์žˆ์Œ maven com.fasterxml.jackson.core jackson-databind 2.13.0 gradle // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.13.0' ์œ„ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ถ”๊ฐ€ํ–ˆ์œผ๋ฉด ์ด ๋‘์ค„๋กœ ์‰ฝ๊ฒŒ ํŒŒ์‹ฑ์ด ๊ฐ€๋Šฅํ•˜๋‹ค! ObjectMapper mapper = new ObjectM.. 2021. 12. 9.
728x90
๋ฐ˜์‘ํ˜•