@Nonnull
@Override
public License deserialize( @Nonnull JsonParser deserializeFrom, @Nonnull Version formatVersion ) throws VersionException, IOException, JsonProcessingException {
//If there is a subtype it *must* be cc
JacksonParserWrapper parserWrapper = new JacksonParserWrapper( deserializeFrom );
parserWrapper.nextToken();
parserWrapper.verifyCurrentToken( JsonToken.FIELD_NAME );
if ( deserializeFrom.getCurrentName().equals( PROPERTY_SUB_TYPE ) ) {
parserWrapper.nextToken();
parserWrapper.verifyCurrentToken( JsonToken.VALUE_STRING );
String subType = deserializeFrom.getText();
if ( !subType.equals( SUB_TYPE_CC ) ) {
throw new IllegalStateException( "Invalid sub type: " + subType );
}
parserWrapper.nextToken();
parserWrapper.verifyCurrentToken( JsonToken.FIELD_NAME );
String currentName = parserWrapper.getCurrentName();
if ( !PROPERTY_ID.equals( currentName ) ) {
throw new JsonParseException( "Invalid field. Expected <" + PROPERTY_ID + "> but was <" + currentName + ">", parserWrapper.getCurrentLocation() );
}
}
//id
assert deserializeFrom.getCurrentName().equals( PROPERTY_ID );
parserWrapper.nextToken();
parserWrapper.verifyCurrentToken( JsonToken.VALUE_STRING );
String id = deserializeFrom.getText();
//name
parserWrapper.nextToken();
parserWrapper.verifyCurrentToken( JsonToken.FIELD_NAME );
String currentName1 = parserWrapper.getCurrentName();
if ( !PROPERTY_NAME.equals( currentName1 ) ) {
throw new JsonParseException( "Invalid field. Expected <" + PROPERTY_NAME + "> but was <" + currentName1 + ">", parserWrapper.getCurrentLocation() );
}
parserWrapper.nextToken();
String name = deserializeFrom.getText();
//url
parserWrapper.nextToken();
parserWrapper.verifyCurrentToken( JsonToken.FIELD_NAME );
String currentName = parserWrapper.getCurrentName();
if ( !PROPERTY_URL.equals( currentName ) ) {
throw new JsonParseException( "Invalid field. Expected <" + PROPERTY_URL + "> but was <" + currentName + ">", parserWrapper.getCurrentLocation() );
}
JsonToken token = deserializeFrom.nextToken();
@Nullable URL url;
if ( token == JsonToken.VALUE_NULL ) {
url = null;
} else {
url = new URL( deserializeFrom.getText() );
}
//Finally closing element
parserWrapper.nextToken( JsonToken.END_OBJECT );
//Constructing the deserialized object
try {
return License.get( id );
} catch ( IllegalArgumentException ignore ) {