Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
twitch
live-coding-fr
Commits
49176d36
Commit
49176d36
authored
Aug 22, 2020
by
Colin DAMON
Browse files
Json configuration and tooling
parent
393f1f76
Changes
2
Hide whitespace changes
Inline
Side-by-side
borestop/src/main/resources/config/application.yml
View file @
49176d36
...
...
@@ -60,6 +60,12 @@ management:
spring
:
application
:
name
:
borestop
jackson
:
default-property-inclusion
:
non_empty
serialization
:
write-dates-as-timestamps
:
false
deserialization
:
fail-on-unknown-properties
:
false
profiles
:
# The commented value for `active` can be replaced with valid Spring profiles to load.
# Otherwise, it will be filled in by maven when building the JAR file
...
...
borestop/src/test/java/com/ippon/borestop/infrastructure/primay/TestJson.java
0 → 100644
View file @
49176d36
package
com.ippon.borestop.infrastructure.primay
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.DeserializationFeature
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.SerializationFeature
;
import
com.fasterxml.jackson.datatype.jdk8.Jdk8Module
;
import
com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
;
import
java.io.IOException
;
public
final
class
TestJson
{
private
static
final
ObjectMapper
jsonMapper
=
jsonMapper
();
private
TestJson
()
{}
public
static
ObjectMapper
jsonMapper
()
{
return
new
ObjectMapper
()
.
setSerializationInclusion
(
JsonInclude
.
Include
.
NON_EMPTY
)
.
registerModule
(
new
JavaTimeModule
())
.
registerModule
(
new
Jdk8Module
())
.
disable
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
)
.
disable
(
DeserializationFeature
.
FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY
)
.
disable
(
SerializationFeature
.
WRITE_DATES_AS_TIMESTAMPS
);
}
public
static
<
T
>
String
writeAsString
(
T
object
)
{
try
{
return
jsonMapper
.
writeValueAsString
(
object
);
}
catch
(
JsonProcessingException
e
)
{
throw
new
AssertionError
(
"Error serializing object: "
+
e
.
getMessage
(),
e
);
}
}
public
static
<
T
>
T
readFromJson
(
String
json
,
Class
<
T
>
clazz
)
{
try
{
return
jsonMapper
.
readValue
(
json
,
clazz
);
}
catch
(
IOException
e
)
{
throw
new
AssertionError
(
"Error reading value from json: "
+
e
.
getMessage
(),
e
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment