com.geotab.model.serialization.StatusDataDeserializer Maven / Gradle / Ivy
/*
*
* 2020 Copyright (C) Geotab Inc. All rights reserved.
*/
package com.geotab.model.serialization;
import static com.geotab.model.serialization.ApiCustomDeserializerModifier.defaultDeserialize;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.geotab.model.entity.statusdata.SensorData;
import com.geotab.model.entity.statusdata.StatusData;
import java.io.IOException;
public class StatusDataDeserializer extends JsonDeserializer {
@Override
public StatusData deserialize(JsonParser jsonParser, DeserializationContext context)
throws IOException {
ObjectCodec parserCodec = jsonParser.getCodec();
JsonNode node = parserCodec.readTree(jsonParser);
if (node.isObject()) {
boolean isSensorData = node.get("address") != null;
if (isSensorData) {
return defaultDeserialize(parserCodec, context, node, SensorData.class);
}
return defaultDeserialize(parserCodec, context, node, StatusData.class);
}
return null;
}
}