@Override public ProtoConstraint deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { if (json == null) { return null; } if (!(json instanceof JsonObject)) { throw new JsonParseException("Expected a JsonObject but found a " + json.getClass().getName()); } JsonObject object = (JsonObject) json; JsonElement typeJson = object.get("type"); ProtoConstraint.Type constraintType = context.deserialize(typeJson, ProtoConstraint.Type.class); Class<? extends ProtoConstraint> subClass = typeClassMap.get(constraintType); if (subClass == null) { throw new JsonParseException("Unable to map constraint type " + constraintType + " to a run constraint class"); } ProtoConstraint constraint = context.deserialize(json, subClass); constraint.validate(); return constraint; } }
@Override public ProtoConstraint deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { if (json == null) { return null; } if (!(json instanceof JsonObject)) { throw new JsonParseException("Expected a JsonObject but found a " + json.getClass().getName()); } JsonObject object = (JsonObject) json; JsonElement typeJson = object.get("type"); ProtoConstraint.Type constraintType = context.deserialize(typeJson, ProtoConstraint.Type.class); Class<? extends ProtoConstraint> subClass = typeClassMap.get(constraintType); if (subClass == null) { throw new JsonParseException("Unable to map constraint type " + constraintType + " to a run constraint class"); } ProtoConstraint constraint = context.deserialize(json, subClass); constraint.validate(); return constraint; } }