๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ‘ฉ‍๐Ÿ’ป Learn programming

[Trouble Shooting] add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling

by ๋ฐ๊ตฅ์ž‰ 2022. 6. 1.
๋ฐ˜์‘ํ˜•

โœ”๏ธ ์„œ์‚ฌ

 

Spring ์›๊ฒฉ ๊ฐ•์˜ ์ค‘์— ์Šคํ”„๋ง์˜ 3๊ณ„์ธต(Controller, Sevice, Repository) ์—†์ด

AllInOneServelet ํด๋ž˜์Šค๋ฅผ ์ƒ์„ฑํ•˜์—ฌ ๊ตฌํ˜„ํ•˜๊ณ , API์˜ ๋™์ž‘์„ ๊ฒ€์ฆํ•˜๊ธฐ ์œ„ํ•œ ์ž‘์—… ์ค‘ ํŠธ๋Ÿฌ๋ธ”์„ ๋งŒ๋‚จ!

 

 

ํŒŒ์ผ ๊ตฌ์„ฑ

 

ARC์—์„œ POST API๋ฅผ ๋ณด๋ƒˆ์„ ๋•Œ, "Internal Server Error"

 

์—๋Ÿฌ ํ™•์ธ์„ ์œ„ํ•ด์„œ intellij ์—๋Ÿฌ ์ฝ”๋“œ ํ™•์ธ

Servlet.service() for servlet [com.sparta.springcore.AllInOneServlet] in context with path [] threw exception

์—๋Ÿฌ ์ฝ”๋“œ ์˜†์— ์žˆ๋Š” ์š” ๋ฌธ์žฅ๋งŒ ์‹ ๊ฒฝ ์“ฐ๋Š๋ผ ๊ฒฝ๋กœ๊ฐ€ ์ž˜๋ชป๋œ ์ค„ ์•Œ๊ณ  PC ์–ธ์–ด ์„ค์ • ๋ณ€๊ฒฝํ•ด๋ณด๊ณ  ๋‚œ๋ฆฌ ... 

 

๊ฒฐ๊ตญ, ํŒ€์›๋ถ„๊ป˜ ๋„์›€์„ ์ฒญํ–ˆ๋Š”๋ฐ ..!

๋ฐ”๋กœ ์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ํ™•์ธํ–ˆ์–ด์•ผํ–ˆ๋‹ค. 

 


โœ”๏ธ Trouble

Java 8 date/time type `java.time.LocalDateTime` not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling (through reference chain: com.sparta.springcore.Product["createdAt"])

 

โœจ ํ•ด๊ฒฐ ์ฐธ๊ณ  ์ž๋ฃŒ 

 

Is there a jackson datatype module for JDK8 java.time?

I'm looking for a module for the new JDK8 java.time classes. I have looked through the FasterXML GitHub Project Listing and presently found none. As I understand Jackson is still being compiled ag...

stackoverflow.com

 

โœ”๏ธ ์›์ธ


Since Jackson 2.6.0 the "old" JSR310Module is deprecated.

It is replaced by JavaTimeModule. Maven dependency is the same (you can find the current version in Maven Central):

(๋ฒˆ์—ญ) Jackson 2.6.0๋ถ€ํ„ฐ "์ด์ „" JSR310Module์€ ๋” ์ด์ƒ ์‚ฌ์šฉ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

JavaTimeModule๋กœ ๋Œ€์ฒด๋ฉ๋‹ˆ๋‹ค. Maven ์ข…์†์„ฑ์€ ๋™์ผํ•ฉ๋‹ˆ๋‹ค(Maven Central์—์„œ ํ˜„์žฌ ๋ฒ„์ „์„ ์ฐพ์„ ์ˆ˜ ์žˆ์Œ).

 

=> Java 8 ๊ณผ์˜ ๋ฒ„์ „ ๋ฌธ์ œ ...

 

 

โœ”๏ธ ํ•ด๊ฒฐ

 

(1) MVN Repository์—์„œ "Jackson Datatype" ๋ฅผ ๊ฒ€์ƒ‰ํ•ด์„œ 'build.gradle - dependencies'์— ๋ถ™์—ฌ์ฃผ๊ธฐ

 

Maven Repository: com.fasterxml.jackson.datatype » jackson-datatype-jsr310 » 2.13.0

Add-on module to support JSR-310 (Java 8 Date & Time API) data types. Note: There is a new version for this artifact com.fasterxml.jackson.datatype jackson-datatype-jsr310 2.13.0 // https://mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-

mvnrepository.com

implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.2'

 

 

(2) AllInOneServlet.java ํด๋ž˜์Šค์—์„œ ์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ์ฐพ์•„์„œ,

ObjectMapper objectMapper = new ObjectMapper();

์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ๋ถ™์—ฌ์ฃผ๊ธฐ (์—ฌ๋Ÿฌ ๊ฐœ ์žˆ์—ˆ์Œ)

objectMapper.registerModule(new JavaTimeModule());

 

โœ”๏ธ ํ•ด๊ฒฐ ์™„๋ฃŒ !

๋ฐ˜์‘ํ˜•