| 1 |
|
package org.europa.together.application; |
| 2 |
|
|
| 3 |
|
import com.fasterxml.jackson.core.type.TypeReference; |
| 4 |
|
import org.europa.together.exceptions.JsonProcessingException; |
| 5 |
|
import com.fasterxml.jackson.databind.ObjectMapper; |
| 6 |
|
import java.util.List; |
| 7 |
|
import org.europa.together.business.JsonTools; |
| 8 |
|
import org.europa.together.business.Logger; |
| 9 |
|
import org.europa.together.domain.LogLevel; |
| 10 |
|
import org.springframework.stereotype.Repository; |
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
@param |
| 16 |
|
|
| 17 |
|
@Repository |
| 18 |
|
@SuppressWarnings("unchecked") |
| |
|
| 91.3% |
Uncovered Elements: 2 (23) |
Complexity: 8 |
Complexity Density: 0.47 |
|
| 19 |
|
public class JacksonJsonTools<T> implements JsonTools<T> { |
| 20 |
|
|
| 21 |
|
private static final long serialVersionUID = 15L; |
| 22 |
|
private static final Logger LOGGER = new LogbackLogger(JacksonJsonTools.class); |
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 27 |
1 |
public JacksonJsonTools() {... |
| 28 |
1 |
LOGGER.log("instance class", LogLevel.INFO); |
| 29 |
|
} |
| 30 |
|
|
| |
|
| 77.8% |
Uncovered Elements: 2 (9) |
Complexity: 3 |
Complexity Density: 0.43 |
|
| 31 |
3 |
@Override... |
| 32 |
|
public String serializeAsJsonObject(final T object) |
| 33 |
|
throws JsonProcessingException { |
| 34 |
3 |
try { |
| 35 |
3 |
if (object == null) { |
| 36 |
1 |
throw new JsonProcessingException("Object is null."); |
| 37 |
|
} |
| 38 |
2 |
ObjectMapper mapper = new ObjectMapper(); |
| 39 |
2 |
return mapper.writeValueAsString(object); |
| 40 |
|
} catch (com.fasterxml.jackson.core.JsonProcessingException ex) { |
| 41 |
0 |
LOGGER.catchException(ex); |
| 42 |
0 |
throw new JsonProcessingException(ex.getOriginalMessage()); |
| 43 |
|
} |
| 44 |
|
} |
| 45 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 46 |
3 |
@Override... |
| 47 |
|
public T deserializeJsonAsObject(final String json, final Class<T> object) |
| 48 |
|
throws JsonProcessingException, ClassNotFoundException { |
| 49 |
3 |
try { |
| 50 |
3 |
Class<?> clazz = Class.forName(object.getCanonicalName()); |
| 51 |
3 |
ObjectMapper mapper = new ObjectMapper(); |
| 52 |
3 |
return (T) mapper.readValue(json, clazz); |
| 53 |
|
} catch (com.fasterxml.jackson.core.JsonProcessingException ex) { |
| 54 |
1 |
throw new JsonProcessingException(ex.getOriginalMessage()); |
| 55 |
|
} |
| 56 |
|
} |
| 57 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 58 |
3 |
@Override... |
| 59 |
|
public List<T> deserializeJsonAsList(final String json) |
| 60 |
|
throws JsonProcessingException, ClassNotFoundException { |
| 61 |
3 |
try { |
| 62 |
3 |
ObjectMapper mapper = new ObjectMapper(); |
| 63 |
3 |
return mapper.readValue(json, new TypeReference<List<T>>() { |
| 64 |
|
}); |
| 65 |
|
} catch (com.fasterxml.jackson.core.JsonProcessingException ex) { |
| 66 |
1 |
throw new JsonProcessingException(ex.getOriginalMessage()); |
| 67 |
|
} |
| 68 |
|
} |
| 69 |
|
} |