Created
September 18, 2017 12:33
-
-
Save andersonkxiass/39cbaa360484d8047bd57202ffdde4e5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class TaskDeserializer extends StdDeserializer<TaskWrapper> { | |
| public TaskDeserializer() { | |
| super(TaskWrapper.class); | |
| } | |
| @Override | |
| public JsonParserUtil deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { | |
| List<Task> trackList = new ArrayList<>(); | |
| TaskWrapper wrapper = new TaskWrapper(); | |
| JsonNode node = jsonParser.getCodec().readTree(jsonParser); | |
| if (node.isArray()) { | |
| for (final JsonNode objNode : node) { | |
| Task task = new Task(); | |
| task.setId(objNode.get("id").asInt()); | |
| task.setName(objNode.get("task_name").asText()); | |
| task.setStatus(objNode.get("status").asText()); | |
| trackList.add(task); | |
| } | |
| } else { | |
| Task task = new Task(); | |
| task.setId(node.get("id").asInt()); | |
| task.setName(node.get("task_name").asText()); | |
| task.setStatus(node.get("status").asText()); | |
| trackList.add(task); | |
| } | |
| wrapper.addTasks(trackList); | |
| return wrapper; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment