-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsonUtils.java
More file actions
26 lines (23 loc) · 852 Bytes
/
JsonUtils.java
File metadata and controls
26 lines (23 loc) · 852 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package cs3500.pa04.JSON;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* Simple utils class used to hold static methods that help with serializing and deserializing JSON.
*/
public class JsonUtils {
/**
* Converts a given record object to a JsonNode.
*
* @param record the record to convert
* @return the JsonNode representation of the given record
* @throws IllegalArgumentException if the record could not be converted correctly
*/
public static JsonNode serializeRecord(Object record) {
try {
ObjectMapper mapper = new ObjectMapper();
return mapper.convertValue(record, JsonNode.class);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Given record cannot be serialized");
}
}
}