All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.geotab.model.serialization.serdes.DiagnosticDeserializer Maven / Gradle / Ivy
package com.geotab.model.serialization.serdes;
import static com.geotab.model.serialization.ApiJsonSerializer.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.diagnostic.BasicDiagnostic;
import com.geotab.model.entity.diagnostic.BrpFaultDiagnostic;
import com.geotab.model.entity.diagnostic.DataDiagnostic;
import com.geotab.model.entity.diagnostic.Diagnostic;
import com.geotab.model.entity.diagnostic.DiagnosticType;
import com.geotab.model.entity.diagnostic.GmcccFaultDiagnostic;
import com.geotab.model.entity.diagnostic.GoDiagnostic;
import com.geotab.model.entity.diagnostic.GoFaultDiagnostic;
import com.geotab.model.entity.diagnostic.LegacyFaultDiagnostic;
import com.geotab.model.entity.diagnostic.NoDiagnostic;
import com.geotab.model.entity.diagnostic.ObdFaultDiagnostic;
import com.geotab.model.entity.diagnostic.ObdSaFaultDiagnostic;
import com.geotab.model.entity.diagnostic.Pid;
import com.geotab.model.entity.diagnostic.ProprietaryFaultDiagnostic;
import com.geotab.model.entity.diagnostic.Sid;
import com.geotab.model.entity.diagnostic.SuspectParameter;
import java.io.IOException;
public class DiagnosticDeserializer extends JsonDeserializer {
@Override
public Diagnostic deserialize(JsonParser jsonParser, DeserializationContext context) throws IOException {
ObjectCodec parserCodec = jsonParser.getCodec();
JsonNode node = parserCodec.readTree(jsonParser);
if (node.isTextual() && NoDiagnostic.NO_DIAGNOSTIC_ID.equals(node.textValue())) return NoDiagnostic.getInstance();
String id = node.get("id") != null ? node.get("id").textValue() : null;
if (NoDiagnostic.NO_DIAGNOSTIC_ID.equals(id)) return NoDiagnostic.getInstance();
DiagnosticType diagnosticType = node.get("diagnosticType") == null ? DiagnosticType.NONE
: parserCodec.treeToValue(node.get("diagnosticType"), DiagnosticType.class);
switch (diagnosticType) {
case DATA_DIAGNOSTIC:
return defaultDeserialize(parserCodec, context, node, DataDiagnostic.class);
case GO_DIAGNOSTIC:
return defaultDeserialize(parserCodec, context, node, GoDiagnostic.class);
case PID:
return defaultDeserialize(parserCodec, context, node, Pid.class);
case SID:
return defaultDeserialize(parserCodec, context, node, Sid.class);
case SUSPECT_PARAMETER:
return defaultDeserialize(parserCodec, context, node, SuspectParameter.class);
case OBD_FAULT:
return defaultDeserialize(parserCodec, context, node, ObdFaultDiagnostic.class);
case GO_FAULT:
return defaultDeserialize(parserCodec, context, node, GoFaultDiagnostic.class);
case OBD_WWH_FAULT:
return defaultDeserialize(parserCodec, context, node, ObdSaFaultDiagnostic.class);
case PROPRIETARY_FAULT:
return defaultDeserialize(parserCodec, context, node, ProprietaryFaultDiagnostic.class);
case LEGACY_FAULT:
return defaultDeserialize(parserCodec, context, node, LegacyFaultDiagnostic.class);
case GMCCC_FAULT:
return defaultDeserialize(parserCodec, context, node, GmcccFaultDiagnostic.class);
case BRP_FAULT:
return defaultDeserialize(parserCodec, context, node, BrpFaultDiagnostic.class);
default:
return defaultDeserialize(parserCodec, context, node, BasicDiagnostic.class);
}
}
}