Skip to content

Commit

Permalink
Add error convert
Browse files Browse the repository at this point in the history
  • Loading branch information
gudaoxuri committed Mar 15, 2017
1 parent f8c4ab3 commit 1fa6f8e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 70 deletions.
18 changes: 6 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<slf4j.version>1.7.22</slf4j.version>
<logback.version>1.1.7</logback.version>
<log4j.version>1.7.21</log4j.version>
<throwing.version>1.3</throwing.version>
<junit.version>4.12</junit.version>
</properties>

Expand All @@ -48,6 +49,11 @@
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>pl.touk</groupId>
<artifactId>throwing-function</artifactId>
<version>${throwing.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down Expand Up @@ -81,18 +87,6 @@
<url>[email protected]:gudaoxuri/dew-common.git</url>
</scm>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<profiles>
<profile>
<id>release</id>
Expand Down
38 changes: 0 additions & 38 deletions src/main/java/com/ecfront/dew/common/FPHelper.java

This file was deleted.

56 changes: 36 additions & 20 deletions src/main/java/com/ecfront/dew/common/JsonHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,44 +30,60 @@ public static void setTimeZone(TimeZone tz) {
MAPPER.setTimeZone(tz);
}

public static String toJsonString(Object obj) throws JsonProcessingException {
public static String toJsonString(Object obj) throws RuntimeException {
if (obj instanceof String) {
return (String) obj;
} else {
return MAPPER.writeValueAsString(obj);
try {
return MAPPER.writeValueAsString(obj);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
}

public static JsonNode toJson(Object obj) throws IOException {
public static JsonNode toJson(Object obj) throws RuntimeException {
if (obj instanceof String) {
return MAPPER.readTree((String) obj);
try {
return MAPPER.readTree((String) obj);
} catch (IOException e) {
throw new RuntimeException(e);
}
} else {
return MAPPER.valueToTree(obj);
}
}

public static <E> List<E> toList(Object obj, Class<E> clazz) throws IOException {
public static <E> List<E> toList(Object obj, Class<E> clazz) throws RuntimeException {
JavaType type = MAPPER.getTypeFactory().constructParametricType(List.class, clazz);
if (obj instanceof String) {
return MAPPER.readValue((String) obj, type);
} else if (obj instanceof JsonNode) {
return MAPPER.readValue(obj.toString(), type);
} else {
return MAPPER.readValue(MAPPER.writeValueAsString(obj), type);
try {
if (obj instanceof String) {
return MAPPER.readValue((String) obj, type);
} else if (obj instanceof JsonNode) {
return MAPPER.readValue(obj.toString(), type);
} else {
return MAPPER.readValue(MAPPER.writeValueAsString(obj), type);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public static <E> E toObject(Object obj, Class<E> clazz) throws IOException {
if (obj instanceof String) {
if (clazz == String.class) {
return (E) obj;
public static <E> E toObject(Object obj, Class<E> clazz) throws RuntimeException {
try {
if (obj instanceof String) {
if (clazz == String.class) {
return (E) obj;
} else {
return MAPPER.readValue((String) obj, clazz);
}
} else if (obj instanceof JsonNode) {
return MAPPER.readValue(obj.toString(), clazz);
} else {
return MAPPER.readValue((String) obj, clazz);
return MAPPER.readValue(MAPPER.writeValueAsString(obj), clazz);
}
} else if (obj instanceof JsonNode) {
return MAPPER.readValue(obj.toString(), clazz);
} else {
return MAPPER.readValue(MAPPER.writeValueAsString(obj), clazz);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

Expand Down

0 comments on commit 1fa6f8e

Please sign in to comment.