-
-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create bean Jdk8Module and ObjectMapper Fix #10751
- Loading branch information
1 parent
bc3f04c
commit 1d56351
Showing
6 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
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
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
15 changes: 15 additions & 0 deletions
15
...pringboot/core/main/wire/jackson/infrastructure/config/JacksonConfiguration.java.mustache
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package {{packageName}}.wire.jackson.infrastructure.config; | ||
|
||
import com.fasterxml.jackson.databind.Module; | ||
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
class JacksonConfiguration { | ||
@Bean | ||
public Module jdk8Module() { | ||
return new Jdk8Module(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...gboot/core/test/wire/jackson/infrastructure/config/JacksonConfigurationTest.java.mustache
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package {{packageName}}.wire.jackson.infrastructure.config; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import {{packageName}}.UnitTest; | ||
import java.util.Optional; | ||
import org.junit.jupiter.api.Test; | ||
|
||
@UnitTest | ||
class JacksonConfigurationTest { | ||
private final JacksonConfiguration jacksonConfiguration = new JacksonConfiguration(); | ||
@Test | ||
void shouldHandleOptional() throws JsonProcessingException { | ||
Optional<String> optional = Optional.of("test"); | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
objectMapper.registerModule(jacksonConfiguration.jdk8Module()); | ||
assertThat(objectMapper.writeValueAsString(optional)).isEqualTo("\"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
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