Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerald Unterrainer committed Jun 18, 2021
2 parents 1cc0393 + 7c6080d commit 32ad7d4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=13
org.eclipse.jdt.core.compiler.compliance=13
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<modelVersion>4.0.0</modelVersion>
<artifactId>serialization</artifactId>
<version>0.1.3</version>
<version>0.1.4</version>
<name>Serialization</name>
<packaging>jar</packaging>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@

import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.TreeNode;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import com.fasterxml.jackson.databind.introspect.AnnotatedClass;
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;

import lombok.AccessLevel;
Expand Down Expand Up @@ -59,6 +60,10 @@ public JsonPOJOBuilder.Value findPOJOBuilderConfig(final AnnotatedClass ac) {
return s;
}

public TypeFactory getTypeFactory() {
return objectMapper.getTypeFactory();
}

public <T> String toStringFrom(final T sourceObject) {
try {
return objectMapper.writeValueAsString(sourceObject);
Expand All @@ -77,9 +82,9 @@ public <T> T fromStringTo(final Class<T> targetClass, final String sourceJson) {
}
}

public <T> T fromTreeTo(final Class<T> targetClass, final TreeNode treeNode) {
public <T> T fromStringTo(final JavaType targetClass, final String sourceJson) {
try {
return objectMapper.treeToValue(treeNode, targetClass);
return objectMapper.readValue(sourceJson, targetClass);
} catch (JsonMappingException e) {
throw new info.unterrainer.commons.serialization.exceptions.JsonMappingException(e.getMessage(), e);
} catch (JsonProcessingException e) {
Expand Down

0 comments on commit 32ad7d4

Please sign in to comment.