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.twitter.clientlib.JSON Maven / Gradle / Ivy
/*
Copyright 2020 Twitter, Inc.
SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
https://openapi-generator.tech
Do not edit the class manually.
*/
package com.twitter.clientlib;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParseException;
import com.google.gson.TypeAdapter;
import com.google.gson.internal.bind.util.ISO8601Utils;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import com.google.gson.JsonElement;
import io.gsonfire.GsonFireBuilder;
import io.gsonfire.TypeSelector;
import okio.ByteString;
import java.io.IOException;
import java.io.StringReader;
import java.lang.reflect.Type;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.ParsePosition;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Locale;
import java.util.Map;
import java.util.HashMap;
/*
* A JSON utility class
*
* NOTE: in the future, this class may be converted to static, which may break
* backward-compatibility
*/
public class JSON {
private static Gson gson;
private static boolean isLenientOnJson = false;
private static DateTypeAdapter dateTypeAdapter = new DateTypeAdapter();
private static SqlDateTypeAdapter sqlDateTypeAdapter = new SqlDateTypeAdapter();
private static OffsetDateTimeTypeAdapter offsetDateTimeTypeAdapter = new OffsetDateTimeTypeAdapter();
private static LocalDateTypeAdapter localDateTypeAdapter = new LocalDateTypeAdapter();
private static ByteArrayAdapter byteArrayAdapter = new ByteArrayAdapter();
@SuppressWarnings("unchecked")
public static GsonBuilder createGson() {
GsonFireBuilder fireBuilder = new GsonFireBuilder()
.registerTypeSelector(com.twitter.clientlib.model.AnimatedGif.class, new TypeSelector() {
@Override
public Class extends com.twitter.clientlib.model.AnimatedGif> getClassForElement(JsonElement readElement) {
Map classByDiscriminatorValue = new HashMap();
classByDiscriminatorValue.put("animated_gif", com.twitter.clientlib.model.AnimatedGif.class);
classByDiscriminatorValue.put("photo", com.twitter.clientlib.model.Photo.class);
classByDiscriminatorValue.put("video", com.twitter.clientlib.model.Video.class);
classByDiscriminatorValue.put("AnimatedGif", com.twitter.clientlib.model.AnimatedGif.class);
return getClassByDiscriminator(classByDiscriminatorValue,
getDiscriminatorValue(readElement, "type"));
}
})
.registerTypeSelector(com.twitter.clientlib.model.ClientDisconnectedProblem.class, new TypeSelector() {
@Override
public Class extends com.twitter.clientlib.model.ClientDisconnectedProblem> getClassForElement(JsonElement readElement) {
Map classByDiscriminatorValue = new HashMap();
classByDiscriminatorValue.put("about:blank", com.twitter.clientlib.model.GenericProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-disconnected", com.twitter.clientlib.model.ClientDisconnectedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-forbidden", com.twitter.clientlib.model.ClientForbiddenProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/conflict", com.twitter.clientlib.model.ConflictProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/disallowed-resource", com.twitter.clientlib.model.DisallowedResourceProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/duplicate-rules", com.twitter.clientlib.model.DuplicateRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-request", com.twitter.clientlib.model.InvalidRequestProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-rules", com.twitter.clientlib.model.InvalidRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/noncompliant-rules", com.twitter.clientlib.model.NonCompliantRulesProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-field", com.twitter.clientlib.model.FieldUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-resource", com.twitter.clientlib.model.ResourceUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/operational-disconnect", com.twitter.clientlib.model.OperationalDisconnectProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-not-found", com.twitter.clientlib.model.ResourceNotFoundProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-unavailable", com.twitter.clientlib.model.ResourceUnavailableProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/rule-cap", com.twitter.clientlib.model.RulesCapProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/streaming-connection", com.twitter.clientlib.model.ConnectionExceptionProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/unsupported-authentication", com.twitter.clientlib.model.UnsupportedAuthenticationProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/usage-capped", com.twitter.clientlib.model.UsageCapExceededProblem.class);
classByDiscriminatorValue.put("ClientDisconnectedProblem", com.twitter.clientlib.model.ClientDisconnectedProblem.class);
return getClassByDiscriminator(classByDiscriminatorValue,
getDiscriminatorValue(readElement, "type"));
}
})
.registerTypeSelector(com.twitter.clientlib.model.ClientForbiddenProblem.class, new TypeSelector() {
@Override
public Class extends com.twitter.clientlib.model.ClientForbiddenProblem> getClassForElement(JsonElement readElement) {
Map classByDiscriminatorValue = new HashMap();
classByDiscriminatorValue.put("about:blank", com.twitter.clientlib.model.GenericProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-disconnected", com.twitter.clientlib.model.ClientDisconnectedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-forbidden", com.twitter.clientlib.model.ClientForbiddenProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/conflict", com.twitter.clientlib.model.ConflictProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/disallowed-resource", com.twitter.clientlib.model.DisallowedResourceProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/duplicate-rules", com.twitter.clientlib.model.DuplicateRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-request", com.twitter.clientlib.model.InvalidRequestProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-rules", com.twitter.clientlib.model.InvalidRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/noncompliant-rules", com.twitter.clientlib.model.NonCompliantRulesProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-field", com.twitter.clientlib.model.FieldUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-resource", com.twitter.clientlib.model.ResourceUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/operational-disconnect", com.twitter.clientlib.model.OperationalDisconnectProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-not-found", com.twitter.clientlib.model.ResourceNotFoundProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-unavailable", com.twitter.clientlib.model.ResourceUnavailableProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/rule-cap", com.twitter.clientlib.model.RulesCapProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/streaming-connection", com.twitter.clientlib.model.ConnectionExceptionProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/unsupported-authentication", com.twitter.clientlib.model.UnsupportedAuthenticationProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/usage-capped", com.twitter.clientlib.model.UsageCapExceededProblem.class);
classByDiscriminatorValue.put("ClientForbiddenProblem", com.twitter.clientlib.model.ClientForbiddenProblem.class);
return getClassByDiscriminator(classByDiscriminatorValue,
getDiscriminatorValue(readElement, "type"));
}
})
.registerTypeSelector(com.twitter.clientlib.model.ConflictProblem.class, new TypeSelector() {
@Override
public Class extends com.twitter.clientlib.model.ConflictProblem> getClassForElement(JsonElement readElement) {
Map classByDiscriminatorValue = new HashMap();
classByDiscriminatorValue.put("about:blank", com.twitter.clientlib.model.GenericProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-disconnected", com.twitter.clientlib.model.ClientDisconnectedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-forbidden", com.twitter.clientlib.model.ClientForbiddenProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/conflict", com.twitter.clientlib.model.ConflictProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/disallowed-resource", com.twitter.clientlib.model.DisallowedResourceProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/duplicate-rules", com.twitter.clientlib.model.DuplicateRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-request", com.twitter.clientlib.model.InvalidRequestProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-rules", com.twitter.clientlib.model.InvalidRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/noncompliant-rules", com.twitter.clientlib.model.NonCompliantRulesProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-field", com.twitter.clientlib.model.FieldUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-resource", com.twitter.clientlib.model.ResourceUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/operational-disconnect", com.twitter.clientlib.model.OperationalDisconnectProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-not-found", com.twitter.clientlib.model.ResourceNotFoundProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-unavailable", com.twitter.clientlib.model.ResourceUnavailableProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/rule-cap", com.twitter.clientlib.model.RulesCapProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/streaming-connection", com.twitter.clientlib.model.ConnectionExceptionProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/unsupported-authentication", com.twitter.clientlib.model.UnsupportedAuthenticationProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/usage-capped", com.twitter.clientlib.model.UsageCapExceededProblem.class);
classByDiscriminatorValue.put("ConflictProblem", com.twitter.clientlib.model.ConflictProblem.class);
return getClassByDiscriminator(classByDiscriminatorValue,
getDiscriminatorValue(readElement, "type"));
}
})
.registerTypeSelector(com.twitter.clientlib.model.ConnectionExceptionProblem.class, new TypeSelector() {
@Override
public Class extends com.twitter.clientlib.model.ConnectionExceptionProblem> getClassForElement(JsonElement readElement) {
Map classByDiscriminatorValue = new HashMap();
classByDiscriminatorValue.put("about:blank", com.twitter.clientlib.model.GenericProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-disconnected", com.twitter.clientlib.model.ClientDisconnectedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-forbidden", com.twitter.clientlib.model.ClientForbiddenProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/conflict", com.twitter.clientlib.model.ConflictProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/disallowed-resource", com.twitter.clientlib.model.DisallowedResourceProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/duplicate-rules", com.twitter.clientlib.model.DuplicateRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-request", com.twitter.clientlib.model.InvalidRequestProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-rules", com.twitter.clientlib.model.InvalidRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/noncompliant-rules", com.twitter.clientlib.model.NonCompliantRulesProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-field", com.twitter.clientlib.model.FieldUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-resource", com.twitter.clientlib.model.ResourceUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/operational-disconnect", com.twitter.clientlib.model.OperationalDisconnectProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-not-found", com.twitter.clientlib.model.ResourceNotFoundProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-unavailable", com.twitter.clientlib.model.ResourceUnavailableProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/rule-cap", com.twitter.clientlib.model.RulesCapProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/streaming-connection", com.twitter.clientlib.model.ConnectionExceptionProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/unsupported-authentication", com.twitter.clientlib.model.UnsupportedAuthenticationProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/usage-capped", com.twitter.clientlib.model.UsageCapExceededProblem.class);
classByDiscriminatorValue.put("ConnectionExceptionProblem", com.twitter.clientlib.model.ConnectionExceptionProblem.class);
return getClassByDiscriminator(classByDiscriminatorValue,
getDiscriminatorValue(readElement, "type"));
}
})
.registerTypeSelector(com.twitter.clientlib.model.DisallowedResourceProblem.class, new TypeSelector() {
@Override
public Class extends com.twitter.clientlib.model.DisallowedResourceProblem> getClassForElement(JsonElement readElement) {
Map classByDiscriminatorValue = new HashMap();
classByDiscriminatorValue.put("about:blank", com.twitter.clientlib.model.GenericProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-disconnected", com.twitter.clientlib.model.ClientDisconnectedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-forbidden", com.twitter.clientlib.model.ClientForbiddenProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/conflict", com.twitter.clientlib.model.ConflictProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/disallowed-resource", com.twitter.clientlib.model.DisallowedResourceProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/duplicate-rules", com.twitter.clientlib.model.DuplicateRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-request", com.twitter.clientlib.model.InvalidRequestProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-rules", com.twitter.clientlib.model.InvalidRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/noncompliant-rules", com.twitter.clientlib.model.NonCompliantRulesProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-field", com.twitter.clientlib.model.FieldUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-resource", com.twitter.clientlib.model.ResourceUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/operational-disconnect", com.twitter.clientlib.model.OperationalDisconnectProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-not-found", com.twitter.clientlib.model.ResourceNotFoundProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-unavailable", com.twitter.clientlib.model.ResourceUnavailableProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/rule-cap", com.twitter.clientlib.model.RulesCapProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/streaming-connection", com.twitter.clientlib.model.ConnectionExceptionProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/unsupported-authentication", com.twitter.clientlib.model.UnsupportedAuthenticationProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/usage-capped", com.twitter.clientlib.model.UsageCapExceededProblem.class);
classByDiscriminatorValue.put("DisallowedResourceProblem", com.twitter.clientlib.model.DisallowedResourceProblem.class);
return getClassByDiscriminator(classByDiscriminatorValue,
getDiscriminatorValue(readElement, "type"));
}
})
.registerTypeSelector(com.twitter.clientlib.model.DuplicateRuleProblem.class, new TypeSelector() {
@Override
public Class extends com.twitter.clientlib.model.DuplicateRuleProblem> getClassForElement(JsonElement readElement) {
Map classByDiscriminatorValue = new HashMap();
classByDiscriminatorValue.put("about:blank", com.twitter.clientlib.model.GenericProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-disconnected", com.twitter.clientlib.model.ClientDisconnectedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-forbidden", com.twitter.clientlib.model.ClientForbiddenProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/conflict", com.twitter.clientlib.model.ConflictProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/disallowed-resource", com.twitter.clientlib.model.DisallowedResourceProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/duplicate-rules", com.twitter.clientlib.model.DuplicateRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-request", com.twitter.clientlib.model.InvalidRequestProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-rules", com.twitter.clientlib.model.InvalidRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/noncompliant-rules", com.twitter.clientlib.model.NonCompliantRulesProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-field", com.twitter.clientlib.model.FieldUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-resource", com.twitter.clientlib.model.ResourceUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/operational-disconnect", com.twitter.clientlib.model.OperationalDisconnectProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-not-found", com.twitter.clientlib.model.ResourceNotFoundProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-unavailable", com.twitter.clientlib.model.ResourceUnavailableProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/rule-cap", com.twitter.clientlib.model.RulesCapProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/streaming-connection", com.twitter.clientlib.model.ConnectionExceptionProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/unsupported-authentication", com.twitter.clientlib.model.UnsupportedAuthenticationProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/usage-capped", com.twitter.clientlib.model.UsageCapExceededProblem.class);
classByDiscriminatorValue.put("DuplicateRuleProblem", com.twitter.clientlib.model.DuplicateRuleProblem.class);
return getClassByDiscriminator(classByDiscriminatorValue,
getDiscriminatorValue(readElement, "type"));
}
})
.registerTypeSelector(com.twitter.clientlib.model.FieldUnauthorizedProblem.class, new TypeSelector() {
@Override
public Class extends com.twitter.clientlib.model.FieldUnauthorizedProblem> getClassForElement(JsonElement readElement) {
Map classByDiscriminatorValue = new HashMap();
classByDiscriminatorValue.put("about:blank", com.twitter.clientlib.model.GenericProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-disconnected", com.twitter.clientlib.model.ClientDisconnectedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-forbidden", com.twitter.clientlib.model.ClientForbiddenProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/conflict", com.twitter.clientlib.model.ConflictProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/disallowed-resource", com.twitter.clientlib.model.DisallowedResourceProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/duplicate-rules", com.twitter.clientlib.model.DuplicateRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-request", com.twitter.clientlib.model.InvalidRequestProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-rules", com.twitter.clientlib.model.InvalidRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/noncompliant-rules", com.twitter.clientlib.model.NonCompliantRulesProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-field", com.twitter.clientlib.model.FieldUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-resource", com.twitter.clientlib.model.ResourceUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/operational-disconnect", com.twitter.clientlib.model.OperationalDisconnectProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-not-found", com.twitter.clientlib.model.ResourceNotFoundProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-unavailable", com.twitter.clientlib.model.ResourceUnavailableProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/rule-cap", com.twitter.clientlib.model.RulesCapProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/streaming-connection", com.twitter.clientlib.model.ConnectionExceptionProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/unsupported-authentication", com.twitter.clientlib.model.UnsupportedAuthenticationProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/usage-capped", com.twitter.clientlib.model.UsageCapExceededProblem.class);
classByDiscriminatorValue.put("FieldUnauthorizedProblem", com.twitter.clientlib.model.FieldUnauthorizedProblem.class);
return getClassByDiscriminator(classByDiscriminatorValue,
getDiscriminatorValue(readElement, "type"));
}
})
.registerTypeSelector(com.twitter.clientlib.model.GenericProblem.class, new TypeSelector() {
@Override
public Class extends com.twitter.clientlib.model.GenericProblem> getClassForElement(JsonElement readElement) {
Map classByDiscriminatorValue = new HashMap();
classByDiscriminatorValue.put("about:blank", com.twitter.clientlib.model.GenericProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-disconnected", com.twitter.clientlib.model.ClientDisconnectedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-forbidden", com.twitter.clientlib.model.ClientForbiddenProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/conflict", com.twitter.clientlib.model.ConflictProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/disallowed-resource", com.twitter.clientlib.model.DisallowedResourceProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/duplicate-rules", com.twitter.clientlib.model.DuplicateRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-request", com.twitter.clientlib.model.InvalidRequestProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-rules", com.twitter.clientlib.model.InvalidRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/noncompliant-rules", com.twitter.clientlib.model.NonCompliantRulesProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-field", com.twitter.clientlib.model.FieldUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-resource", com.twitter.clientlib.model.ResourceUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/operational-disconnect", com.twitter.clientlib.model.OperationalDisconnectProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-not-found", com.twitter.clientlib.model.ResourceNotFoundProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-unavailable", com.twitter.clientlib.model.ResourceUnavailableProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/rule-cap", com.twitter.clientlib.model.RulesCapProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/streaming-connection", com.twitter.clientlib.model.ConnectionExceptionProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/unsupported-authentication", com.twitter.clientlib.model.UnsupportedAuthenticationProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/usage-capped", com.twitter.clientlib.model.UsageCapExceededProblem.class);
classByDiscriminatorValue.put("GenericProblem", com.twitter.clientlib.model.GenericProblem.class);
return getClassByDiscriminator(classByDiscriminatorValue,
getDiscriminatorValue(readElement, "type"));
}
})
.registerTypeSelector(com.twitter.clientlib.model.InvalidRequestProblem.class, new TypeSelector() {
@Override
public Class extends com.twitter.clientlib.model.InvalidRequestProblem> getClassForElement(JsonElement readElement) {
Map classByDiscriminatorValue = new HashMap();
classByDiscriminatorValue.put("about:blank", com.twitter.clientlib.model.GenericProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-disconnected", com.twitter.clientlib.model.ClientDisconnectedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-forbidden", com.twitter.clientlib.model.ClientForbiddenProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/conflict", com.twitter.clientlib.model.ConflictProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/disallowed-resource", com.twitter.clientlib.model.DisallowedResourceProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/duplicate-rules", com.twitter.clientlib.model.DuplicateRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-request", com.twitter.clientlib.model.InvalidRequestProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-rules", com.twitter.clientlib.model.InvalidRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/noncompliant-rules", com.twitter.clientlib.model.NonCompliantRulesProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-field", com.twitter.clientlib.model.FieldUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-resource", com.twitter.clientlib.model.ResourceUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/operational-disconnect", com.twitter.clientlib.model.OperationalDisconnectProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-not-found", com.twitter.clientlib.model.ResourceNotFoundProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-unavailable", com.twitter.clientlib.model.ResourceUnavailableProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/rule-cap", com.twitter.clientlib.model.RulesCapProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/streaming-connection", com.twitter.clientlib.model.ConnectionExceptionProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/unsupported-authentication", com.twitter.clientlib.model.UnsupportedAuthenticationProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/usage-capped", com.twitter.clientlib.model.UsageCapExceededProblem.class);
classByDiscriminatorValue.put("InvalidRequestProblem", com.twitter.clientlib.model.InvalidRequestProblem.class);
return getClassByDiscriminator(classByDiscriminatorValue,
getDiscriminatorValue(readElement, "type"));
}
})
.registerTypeSelector(com.twitter.clientlib.model.InvalidRuleProblem.class, new TypeSelector() {
@Override
public Class extends com.twitter.clientlib.model.InvalidRuleProblem> getClassForElement(JsonElement readElement) {
Map classByDiscriminatorValue = new HashMap();
classByDiscriminatorValue.put("about:blank", com.twitter.clientlib.model.GenericProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-disconnected", com.twitter.clientlib.model.ClientDisconnectedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-forbidden", com.twitter.clientlib.model.ClientForbiddenProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/conflict", com.twitter.clientlib.model.ConflictProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/disallowed-resource", com.twitter.clientlib.model.DisallowedResourceProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/duplicate-rules", com.twitter.clientlib.model.DuplicateRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-request", com.twitter.clientlib.model.InvalidRequestProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-rules", com.twitter.clientlib.model.InvalidRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/noncompliant-rules", com.twitter.clientlib.model.NonCompliantRulesProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-field", com.twitter.clientlib.model.FieldUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-resource", com.twitter.clientlib.model.ResourceUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/operational-disconnect", com.twitter.clientlib.model.OperationalDisconnectProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-not-found", com.twitter.clientlib.model.ResourceNotFoundProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-unavailable", com.twitter.clientlib.model.ResourceUnavailableProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/rule-cap", com.twitter.clientlib.model.RulesCapProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/streaming-connection", com.twitter.clientlib.model.ConnectionExceptionProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/unsupported-authentication", com.twitter.clientlib.model.UnsupportedAuthenticationProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/usage-capped", com.twitter.clientlib.model.UsageCapExceededProblem.class);
classByDiscriminatorValue.put("InvalidRuleProblem", com.twitter.clientlib.model.InvalidRuleProblem.class);
return getClassByDiscriminator(classByDiscriminatorValue,
getDiscriminatorValue(readElement, "type"));
}
})
.registerTypeSelector(com.twitter.clientlib.model.Media.class, new TypeSelector() {
@Override
public Class extends com.twitter.clientlib.model.Media> getClassForElement(JsonElement readElement) {
Map classByDiscriminatorValue = new HashMap();
classByDiscriminatorValue.put("AnimatedGif", com.twitter.clientlib.model.AnimatedGif.class);
classByDiscriminatorValue.put("Photo", com.twitter.clientlib.model.Photo.class);
classByDiscriminatorValue.put("Video", com.twitter.clientlib.model.Video.class);
classByDiscriminatorValue.put("animated_gif", com.twitter.clientlib.model.AnimatedGif.class);
classByDiscriminatorValue.put("photo", com.twitter.clientlib.model.Photo.class);
classByDiscriminatorValue.put("video", com.twitter.clientlib.model.Video.class);
classByDiscriminatorValue.put("Media", com.twitter.clientlib.model.Media.class);
return getClassByDiscriminator(classByDiscriminatorValue,
getDiscriminatorValue(readElement, "type"));
}
})
.registerTypeSelector(com.twitter.clientlib.model.NonCompliantRulesProblem.class, new TypeSelector() {
@Override
public Class extends com.twitter.clientlib.model.NonCompliantRulesProblem> getClassForElement(JsonElement readElement) {
Map classByDiscriminatorValue = new HashMap();
classByDiscriminatorValue.put("about:blank", com.twitter.clientlib.model.GenericProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-disconnected", com.twitter.clientlib.model.ClientDisconnectedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-forbidden", com.twitter.clientlib.model.ClientForbiddenProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/conflict", com.twitter.clientlib.model.ConflictProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/disallowed-resource", com.twitter.clientlib.model.DisallowedResourceProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/duplicate-rules", com.twitter.clientlib.model.DuplicateRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-request", com.twitter.clientlib.model.InvalidRequestProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-rules", com.twitter.clientlib.model.InvalidRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/noncompliant-rules", com.twitter.clientlib.model.NonCompliantRulesProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-field", com.twitter.clientlib.model.FieldUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-resource", com.twitter.clientlib.model.ResourceUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/operational-disconnect", com.twitter.clientlib.model.OperationalDisconnectProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-not-found", com.twitter.clientlib.model.ResourceNotFoundProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-unavailable", com.twitter.clientlib.model.ResourceUnavailableProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/rule-cap", com.twitter.clientlib.model.RulesCapProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/streaming-connection", com.twitter.clientlib.model.ConnectionExceptionProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/unsupported-authentication", com.twitter.clientlib.model.UnsupportedAuthenticationProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/usage-capped", com.twitter.clientlib.model.UsageCapExceededProblem.class);
classByDiscriminatorValue.put("NonCompliantRulesProblem", com.twitter.clientlib.model.NonCompliantRulesProblem.class);
return getClassByDiscriminator(classByDiscriminatorValue,
getDiscriminatorValue(readElement, "type"));
}
})
.registerTypeSelector(com.twitter.clientlib.model.OperationalDisconnectProblem.class, new TypeSelector() {
@Override
public Class extends com.twitter.clientlib.model.OperationalDisconnectProblem> getClassForElement(JsonElement readElement) {
Map classByDiscriminatorValue = new HashMap();
classByDiscriminatorValue.put("about:blank", com.twitter.clientlib.model.GenericProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-disconnected", com.twitter.clientlib.model.ClientDisconnectedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-forbidden", com.twitter.clientlib.model.ClientForbiddenProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/conflict", com.twitter.clientlib.model.ConflictProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/disallowed-resource", com.twitter.clientlib.model.DisallowedResourceProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/duplicate-rules", com.twitter.clientlib.model.DuplicateRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-request", com.twitter.clientlib.model.InvalidRequestProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-rules", com.twitter.clientlib.model.InvalidRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/noncompliant-rules", com.twitter.clientlib.model.NonCompliantRulesProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-field", com.twitter.clientlib.model.FieldUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-resource", com.twitter.clientlib.model.ResourceUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/operational-disconnect", com.twitter.clientlib.model.OperationalDisconnectProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-not-found", com.twitter.clientlib.model.ResourceNotFoundProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-unavailable", com.twitter.clientlib.model.ResourceUnavailableProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/rule-cap", com.twitter.clientlib.model.RulesCapProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/streaming-connection", com.twitter.clientlib.model.ConnectionExceptionProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/unsupported-authentication", com.twitter.clientlib.model.UnsupportedAuthenticationProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/usage-capped", com.twitter.clientlib.model.UsageCapExceededProblem.class);
classByDiscriminatorValue.put("OperationalDisconnectProblem", com.twitter.clientlib.model.OperationalDisconnectProblem.class);
return getClassByDiscriminator(classByDiscriminatorValue,
getDiscriminatorValue(readElement, "type"));
}
})
.registerTypeSelector(com.twitter.clientlib.model.Photo.class, new TypeSelector() {
@Override
public Class extends com.twitter.clientlib.model.Photo> getClassForElement(JsonElement readElement) {
Map classByDiscriminatorValue = new HashMap();
classByDiscriminatorValue.put("animated_gif", com.twitter.clientlib.model.AnimatedGif.class);
classByDiscriminatorValue.put("photo", com.twitter.clientlib.model.Photo.class);
classByDiscriminatorValue.put("video", com.twitter.clientlib.model.Video.class);
classByDiscriminatorValue.put("Photo", com.twitter.clientlib.model.Photo.class);
return getClassByDiscriminator(classByDiscriminatorValue,
getDiscriminatorValue(readElement, "type"));
}
})
.registerTypeSelector(com.twitter.clientlib.model.Problem.class, new TypeSelector() {
@Override
public Class extends com.twitter.clientlib.model.Problem> getClassForElement(JsonElement readElement) {
Map classByDiscriminatorValue = new HashMap();
classByDiscriminatorValue.put("ClientDisconnectedProblem", com.twitter.clientlib.model.ClientDisconnectedProblem.class);
classByDiscriminatorValue.put("ClientForbiddenProblem", com.twitter.clientlib.model.ClientForbiddenProblem.class);
classByDiscriminatorValue.put("ConflictProblem", com.twitter.clientlib.model.ConflictProblem.class);
classByDiscriminatorValue.put("ConnectionExceptionProblem", com.twitter.clientlib.model.ConnectionExceptionProblem.class);
classByDiscriminatorValue.put("DisallowedResourceProblem", com.twitter.clientlib.model.DisallowedResourceProblem.class);
classByDiscriminatorValue.put("DuplicateRuleProblem", com.twitter.clientlib.model.DuplicateRuleProblem.class);
classByDiscriminatorValue.put("FieldUnauthorizedProblem", com.twitter.clientlib.model.FieldUnauthorizedProblem.class);
classByDiscriminatorValue.put("GenericProblem", com.twitter.clientlib.model.GenericProblem.class);
classByDiscriminatorValue.put("InvalidRequestProblem", com.twitter.clientlib.model.InvalidRequestProblem.class);
classByDiscriminatorValue.put("InvalidRuleProblem", com.twitter.clientlib.model.InvalidRuleProblem.class);
classByDiscriminatorValue.put("NonCompliantRulesProblem", com.twitter.clientlib.model.NonCompliantRulesProblem.class);
classByDiscriminatorValue.put("OperationalDisconnectProblem", com.twitter.clientlib.model.OperationalDisconnectProblem.class);
classByDiscriminatorValue.put("ResourceNotFoundProblem", com.twitter.clientlib.model.ResourceNotFoundProblem.class);
classByDiscriminatorValue.put("ResourceUnauthorizedProblem", com.twitter.clientlib.model.ResourceUnauthorizedProblem.class);
classByDiscriminatorValue.put("ResourceUnavailableProblem", com.twitter.clientlib.model.ResourceUnavailableProblem.class);
classByDiscriminatorValue.put("RulesCapProblem", com.twitter.clientlib.model.RulesCapProblem.class);
classByDiscriminatorValue.put("UnsupportedAuthenticationProblem", com.twitter.clientlib.model.UnsupportedAuthenticationProblem.class);
classByDiscriminatorValue.put("UsageCapExceededProblem", com.twitter.clientlib.model.UsageCapExceededProblem.class);
classByDiscriminatorValue.put("about:blank", com.twitter.clientlib.model.GenericProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-disconnected", com.twitter.clientlib.model.ClientDisconnectedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-forbidden", com.twitter.clientlib.model.ClientForbiddenProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/conflict", com.twitter.clientlib.model.ConflictProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/disallowed-resource", com.twitter.clientlib.model.DisallowedResourceProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/duplicate-rules", com.twitter.clientlib.model.DuplicateRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-request", com.twitter.clientlib.model.InvalidRequestProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-rules", com.twitter.clientlib.model.InvalidRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/noncompliant-rules", com.twitter.clientlib.model.NonCompliantRulesProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-field", com.twitter.clientlib.model.FieldUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-resource", com.twitter.clientlib.model.ResourceUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/operational-disconnect", com.twitter.clientlib.model.OperationalDisconnectProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-not-found", com.twitter.clientlib.model.ResourceNotFoundProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-unavailable", com.twitter.clientlib.model.ResourceUnavailableProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/rule-cap", com.twitter.clientlib.model.RulesCapProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/streaming-connection", com.twitter.clientlib.model.ConnectionExceptionProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/unsupported-authentication", com.twitter.clientlib.model.UnsupportedAuthenticationProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/usage-capped", com.twitter.clientlib.model.UsageCapExceededProblem.class);
classByDiscriminatorValue.put("Problem", com.twitter.clientlib.model.Problem.class);
return getClassByDiscriminator(classByDiscriminatorValue,
getDiscriminatorValue(readElement, "type"));
}
})
.registerTypeSelector(com.twitter.clientlib.model.ResourceNotFoundProblem.class, new TypeSelector() {
@Override
public Class extends com.twitter.clientlib.model.ResourceNotFoundProblem> getClassForElement(JsonElement readElement) {
Map classByDiscriminatorValue = new HashMap();
classByDiscriminatorValue.put("about:blank", com.twitter.clientlib.model.GenericProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-disconnected", com.twitter.clientlib.model.ClientDisconnectedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-forbidden", com.twitter.clientlib.model.ClientForbiddenProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/conflict", com.twitter.clientlib.model.ConflictProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/disallowed-resource", com.twitter.clientlib.model.DisallowedResourceProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/duplicate-rules", com.twitter.clientlib.model.DuplicateRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-request", com.twitter.clientlib.model.InvalidRequestProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-rules", com.twitter.clientlib.model.InvalidRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/noncompliant-rules", com.twitter.clientlib.model.NonCompliantRulesProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-field", com.twitter.clientlib.model.FieldUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-resource", com.twitter.clientlib.model.ResourceUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/operational-disconnect", com.twitter.clientlib.model.OperationalDisconnectProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-not-found", com.twitter.clientlib.model.ResourceNotFoundProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-unavailable", com.twitter.clientlib.model.ResourceUnavailableProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/rule-cap", com.twitter.clientlib.model.RulesCapProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/streaming-connection", com.twitter.clientlib.model.ConnectionExceptionProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/unsupported-authentication", com.twitter.clientlib.model.UnsupportedAuthenticationProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/usage-capped", com.twitter.clientlib.model.UsageCapExceededProblem.class);
classByDiscriminatorValue.put("ResourceNotFoundProblem", com.twitter.clientlib.model.ResourceNotFoundProblem.class);
return getClassByDiscriminator(classByDiscriminatorValue,
getDiscriminatorValue(readElement, "type"));
}
})
.registerTypeSelector(com.twitter.clientlib.model.ResourceUnauthorizedProblem.class, new TypeSelector() {
@Override
public Class extends com.twitter.clientlib.model.ResourceUnauthorizedProblem> getClassForElement(JsonElement readElement) {
Map classByDiscriminatorValue = new HashMap();
classByDiscriminatorValue.put("about:blank", com.twitter.clientlib.model.GenericProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-disconnected", com.twitter.clientlib.model.ClientDisconnectedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-forbidden", com.twitter.clientlib.model.ClientForbiddenProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/conflict", com.twitter.clientlib.model.ConflictProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/disallowed-resource", com.twitter.clientlib.model.DisallowedResourceProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/duplicate-rules", com.twitter.clientlib.model.DuplicateRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-request", com.twitter.clientlib.model.InvalidRequestProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-rules", com.twitter.clientlib.model.InvalidRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/noncompliant-rules", com.twitter.clientlib.model.NonCompliantRulesProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-field", com.twitter.clientlib.model.FieldUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-resource", com.twitter.clientlib.model.ResourceUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/operational-disconnect", com.twitter.clientlib.model.OperationalDisconnectProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-not-found", com.twitter.clientlib.model.ResourceNotFoundProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-unavailable", com.twitter.clientlib.model.ResourceUnavailableProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/rule-cap", com.twitter.clientlib.model.RulesCapProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/streaming-connection", com.twitter.clientlib.model.ConnectionExceptionProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/unsupported-authentication", com.twitter.clientlib.model.UnsupportedAuthenticationProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/usage-capped", com.twitter.clientlib.model.UsageCapExceededProblem.class);
classByDiscriminatorValue.put("ResourceUnauthorizedProblem", com.twitter.clientlib.model.ResourceUnauthorizedProblem.class);
return getClassByDiscriminator(classByDiscriminatorValue,
getDiscriminatorValue(readElement, "type"));
}
})
.registerTypeSelector(com.twitter.clientlib.model.ResourceUnavailableProblem.class, new TypeSelector() {
@Override
public Class extends com.twitter.clientlib.model.ResourceUnavailableProblem> getClassForElement(JsonElement readElement) {
Map classByDiscriminatorValue = new HashMap();
classByDiscriminatorValue.put("about:blank", com.twitter.clientlib.model.GenericProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-disconnected", com.twitter.clientlib.model.ClientDisconnectedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-forbidden", com.twitter.clientlib.model.ClientForbiddenProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/conflict", com.twitter.clientlib.model.ConflictProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/disallowed-resource", com.twitter.clientlib.model.DisallowedResourceProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/duplicate-rules", com.twitter.clientlib.model.DuplicateRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-request", com.twitter.clientlib.model.InvalidRequestProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-rules", com.twitter.clientlib.model.InvalidRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/noncompliant-rules", com.twitter.clientlib.model.NonCompliantRulesProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-field", com.twitter.clientlib.model.FieldUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-resource", com.twitter.clientlib.model.ResourceUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/operational-disconnect", com.twitter.clientlib.model.OperationalDisconnectProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-not-found", com.twitter.clientlib.model.ResourceNotFoundProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-unavailable", com.twitter.clientlib.model.ResourceUnavailableProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/rule-cap", com.twitter.clientlib.model.RulesCapProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/streaming-connection", com.twitter.clientlib.model.ConnectionExceptionProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/unsupported-authentication", com.twitter.clientlib.model.UnsupportedAuthenticationProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/usage-capped", com.twitter.clientlib.model.UsageCapExceededProblem.class);
classByDiscriminatorValue.put("ResourceUnavailableProblem", com.twitter.clientlib.model.ResourceUnavailableProblem.class);
return getClassByDiscriminator(classByDiscriminatorValue,
getDiscriminatorValue(readElement, "type"));
}
})
.registerTypeSelector(com.twitter.clientlib.model.RulesCapProblem.class, new TypeSelector() {
@Override
public Class extends com.twitter.clientlib.model.RulesCapProblem> getClassForElement(JsonElement readElement) {
Map classByDiscriminatorValue = new HashMap();
classByDiscriminatorValue.put("about:blank", com.twitter.clientlib.model.GenericProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-disconnected", com.twitter.clientlib.model.ClientDisconnectedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-forbidden", com.twitter.clientlib.model.ClientForbiddenProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/conflict", com.twitter.clientlib.model.ConflictProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/disallowed-resource", com.twitter.clientlib.model.DisallowedResourceProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/duplicate-rules", com.twitter.clientlib.model.DuplicateRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-request", com.twitter.clientlib.model.InvalidRequestProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-rules", com.twitter.clientlib.model.InvalidRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/noncompliant-rules", com.twitter.clientlib.model.NonCompliantRulesProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-field", com.twitter.clientlib.model.FieldUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-resource", com.twitter.clientlib.model.ResourceUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/operational-disconnect", com.twitter.clientlib.model.OperationalDisconnectProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-not-found", com.twitter.clientlib.model.ResourceNotFoundProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-unavailable", com.twitter.clientlib.model.ResourceUnavailableProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/rule-cap", com.twitter.clientlib.model.RulesCapProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/streaming-connection", com.twitter.clientlib.model.ConnectionExceptionProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/unsupported-authentication", com.twitter.clientlib.model.UnsupportedAuthenticationProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/usage-capped", com.twitter.clientlib.model.UsageCapExceededProblem.class);
classByDiscriminatorValue.put("RulesCapProblem", com.twitter.clientlib.model.RulesCapProblem.class);
return getClassByDiscriminator(classByDiscriminatorValue,
getDiscriminatorValue(readElement, "type"));
}
})
.registerTypeSelector(com.twitter.clientlib.model.UnsupportedAuthenticationProblem.class, new TypeSelector() {
@Override
public Class extends com.twitter.clientlib.model.UnsupportedAuthenticationProblem> getClassForElement(JsonElement readElement) {
Map classByDiscriminatorValue = new HashMap();
classByDiscriminatorValue.put("about:blank", com.twitter.clientlib.model.GenericProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-disconnected", com.twitter.clientlib.model.ClientDisconnectedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-forbidden", com.twitter.clientlib.model.ClientForbiddenProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/conflict", com.twitter.clientlib.model.ConflictProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/disallowed-resource", com.twitter.clientlib.model.DisallowedResourceProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/duplicate-rules", com.twitter.clientlib.model.DuplicateRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-request", com.twitter.clientlib.model.InvalidRequestProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-rules", com.twitter.clientlib.model.InvalidRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/noncompliant-rules", com.twitter.clientlib.model.NonCompliantRulesProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-field", com.twitter.clientlib.model.FieldUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-resource", com.twitter.clientlib.model.ResourceUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/operational-disconnect", com.twitter.clientlib.model.OperationalDisconnectProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-not-found", com.twitter.clientlib.model.ResourceNotFoundProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-unavailable", com.twitter.clientlib.model.ResourceUnavailableProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/rule-cap", com.twitter.clientlib.model.RulesCapProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/streaming-connection", com.twitter.clientlib.model.ConnectionExceptionProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/unsupported-authentication", com.twitter.clientlib.model.UnsupportedAuthenticationProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/usage-capped", com.twitter.clientlib.model.UsageCapExceededProblem.class);
classByDiscriminatorValue.put("UnsupportedAuthenticationProblem", com.twitter.clientlib.model.UnsupportedAuthenticationProblem.class);
return getClassByDiscriminator(classByDiscriminatorValue,
getDiscriminatorValue(readElement, "type"));
}
})
.registerTypeSelector(com.twitter.clientlib.model.UsageCapExceededProblem.class, new TypeSelector() {
@Override
public Class extends com.twitter.clientlib.model.UsageCapExceededProblem> getClassForElement(JsonElement readElement) {
Map classByDiscriminatorValue = new HashMap();
classByDiscriminatorValue.put("about:blank", com.twitter.clientlib.model.GenericProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-disconnected", com.twitter.clientlib.model.ClientDisconnectedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/client-forbidden", com.twitter.clientlib.model.ClientForbiddenProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/conflict", com.twitter.clientlib.model.ConflictProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/disallowed-resource", com.twitter.clientlib.model.DisallowedResourceProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/duplicate-rules", com.twitter.clientlib.model.DuplicateRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-request", com.twitter.clientlib.model.InvalidRequestProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/invalid-rules", com.twitter.clientlib.model.InvalidRuleProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/noncompliant-rules", com.twitter.clientlib.model.NonCompliantRulesProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-field", com.twitter.clientlib.model.FieldUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/not-authorized-for-resource", com.twitter.clientlib.model.ResourceUnauthorizedProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/operational-disconnect", com.twitter.clientlib.model.OperationalDisconnectProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-not-found", com.twitter.clientlib.model.ResourceNotFoundProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/resource-unavailable", com.twitter.clientlib.model.ResourceUnavailableProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/rule-cap", com.twitter.clientlib.model.RulesCapProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/streaming-connection", com.twitter.clientlib.model.ConnectionExceptionProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/unsupported-authentication", com.twitter.clientlib.model.UnsupportedAuthenticationProblem.class);
classByDiscriminatorValue.put("https://api.twitter.com/2/problems/usage-capped", com.twitter.clientlib.model.UsageCapExceededProblem.class);
classByDiscriminatorValue.put("UsageCapExceededProblem", com.twitter.clientlib.model.UsageCapExceededProblem.class);
return getClassByDiscriminator(classByDiscriminatorValue,
getDiscriminatorValue(readElement, "type"));
}
})
.registerTypeSelector(com.twitter.clientlib.model.Video.class, new TypeSelector() {
@Override
public Class extends com.twitter.clientlib.model.Video> getClassForElement(JsonElement readElement) {
Map classByDiscriminatorValue = new HashMap();
classByDiscriminatorValue.put("animated_gif", com.twitter.clientlib.model.AnimatedGif.class);
classByDiscriminatorValue.put("photo", com.twitter.clientlib.model.Photo.class);
classByDiscriminatorValue.put("video", com.twitter.clientlib.model.Video.class);
classByDiscriminatorValue.put("Video", com.twitter.clientlib.model.Video.class);
return getClassByDiscriminator(classByDiscriminatorValue,
getDiscriminatorValue(readElement, "type"));
}
})
;
GsonBuilder builder = fireBuilder.createGsonBuilder();
return builder;
}
private static String getDiscriminatorValue(JsonElement readElement, String discriminatorField) {
JsonElement element = readElement.getAsJsonObject().get(discriminatorField);
if (null == element) {
throw new IllegalArgumentException("missing discriminator field: <" + discriminatorField + ">");
}
return element.getAsString();
}
/**
* Returns the Java class that implements the OpenAPI schema for the specified discriminator value.
*
* @param classByDiscriminatorValue The map of discriminator values to Java classes.
* @param discriminatorValue The value of the OpenAPI discriminator in the input data.
* @return The Java class that implements the OpenAPI schema
*/
private static Class getClassByDiscriminator(Map classByDiscriminatorValue, String discriminatorValue) {
Class clazz = (Class) classByDiscriminatorValue.get(discriminatorValue);
if (null == clazz) {
throw new IllegalArgumentException("cannot determine model class of name: <" + discriminatorValue + ">");
}
return clazz;
}
{
gson = createGson()
.registerTypeAdapter(Date.class, dateTypeAdapter)
.registerTypeAdapter(java.sql.Date.class, sqlDateTypeAdapter)
.registerTypeAdapter(OffsetDateTime.class, offsetDateTimeTypeAdapter)
.registerTypeAdapter(LocalDate.class, localDateTypeAdapter)
.registerTypeAdapter(byte[].class, byteArrayAdapter)
.registerTypeAdapterFactory(new com.twitter.clientlib.model.AddBookmarkRequest.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.AddOrDeleteRulesRequest.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.AddOrDeleteRulesResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.AddRulesRequest.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.AnimatedGif.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.AnimatedGifAllOf.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.BookmarkMutationResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.BookmarkMutationResponseData.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.CashtagEntity.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.CashtagFields.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ClientDisconnectedProblem.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ClientForbiddenProblem.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ClientForbiddenProblemAllOf.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ComplianceJob.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ConflictProblem.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ConnectionExceptionProblem.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ConnectionExceptionProblemAllOf.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ContextAnnotation.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ContextAnnotationDomainFields.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ContextAnnotationEntityFields.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.CreateBatchComplianceJobRequest.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.CreateTweetRequest.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.CreateTweetRequestGeo.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.CreateTweetRequestMedia.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.CreateTweetRequestPoll.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.CreateTweetRequestReply.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.DeleteRulesRequest.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.DeleteRulesRequestDelete.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.DisallowedResourceProblem.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.DisallowedResourceProblemAllOf.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.DuplicateRuleProblem.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.DuplicateRuleProblemAllOf.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.EntityIndicesInclusiveExclusive.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.EntityIndicesInclusiveInclusive.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.Error.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.Expansions.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.FieldUnauthorizedProblem.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.FieldUnauthorizedProblemAllOf.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.FilteredStreamingTweet.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.FilteredStreamingTweetOneOf.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.FilteredStreamingTweetOneOf1.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.FilteredStreamingTweetOneOfMatchingRules.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.FullTextEntities.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.GenericMultipleUsersLookupResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.GenericMultipleUsersLookupResponseMeta.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.GenericProblem.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.GenericTweetsTimelineResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.GenericTweetsTimelineResponseMeta.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.Geo.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.GetRulesResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.HashtagEntity.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.HashtagFields.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.HideReplyByIdRequest.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.HideReplyByIdResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.HideReplyByIdResponseData.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.InvalidRequestProblem.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.InvalidRequestProblemAllOf.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.InvalidRequestProblemAllOfErrors.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.InvalidRuleProblem.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ListAddMemberRequest.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ListCreateRequest.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ListCreateResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ListDeleteResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ListDeleteResponseData.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ListFollowRequest.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ListFollowedResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ListFollowedResponseData.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ListLookupMultipleUsersLookupResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ListLookupMultipleUsersLookupResponseMeta.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ListMemberResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ListMemberResponseData.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ListPinRequest.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ListPinnedResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ListPinnedResponseData.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ListUpdateRequest.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ListUpdateResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ListUpdateResponseData.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ListsIdTweetsResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.MentionEntity.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.MentionFields.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ModelList.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.MultiComplianceJobResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.MultiListNoPaginationResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.MultiListNoPaginationResponseMeta.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.MultiListResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.MultiListResponseMeta.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.MultiSpaceLookupResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.MultiTweetLookupResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.MultiTweetLookupResponseMeta.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.MultiUserLookupResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.NonCompliantRulesProblem.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.OperationalDisconnectProblem.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.OperationalDisconnectProblemAllOf.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.Photo.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.PhotoAllOf.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.Place.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.Point.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.Poll.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.PollOption.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ProblemOrError.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.QuoteTweetLookupResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.QuoteTweetLookupResponseMeta.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ResourceNotFoundProblem.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ResourceNotFoundProblemAllOf.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ResourceUnauthorizedProblem.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ResourceUnauthorizedProblemAllOf.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ResourceUnavailableProblem.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.ResourceUnavailableProblemAllOf.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.Rule.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.RuleNoId.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.RulesCapProblem.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.RulesRequestSummary.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.RulesRequestSummaryOneOf.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.RulesRequestSummaryOneOf1.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.RulesResponseMetadata.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.SearchCount.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.SingleComplianceJobResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.SingleListLookupResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.SingleListLookupResponseIncludes.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.SingleSpaceLookupResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.SingleTweetLookupResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.SingleUserLookupResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.Space.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.SpaceTopics.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.StreamingTweet.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.Tweet.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.TweetAttachments.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.TweetCountsResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.TweetCountsResponseMeta.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.TweetCreateResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.TweetCreateResponseData.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.TweetDeleteResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.TweetDeleteResponseData.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.TweetGeo.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.TweetNonPublicMetrics.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.TweetOrganicMetrics.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.TweetPromotedMetrics.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.TweetPublicMetrics.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.TweetReferencedTweets.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.TweetSearchResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.TweetSearchResponseMeta.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.TweetWithheld.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.URLFields.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.URLImage.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.UnsupportedAuthenticationProblem.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.UrlEntity.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.UsageCapExceededProblem.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.UsageCapExceededProblemAllOf.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.User.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.UserEntities.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.UserEntitiesUrl.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.UserPublicMetrics.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.UserWithheld.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.UsersBlockingMutationResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.UsersBlockingMutationResponseData.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.UsersFollowingCreateResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.UsersFollowingCreateResponseData.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.UsersFollowingDeleteResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.UsersFollowingLookupResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.UsersIdBlockRequest.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.UsersIdFollowRequest.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.UsersIdLikedTweetsResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.UsersIdLikedTweetsResponseMeta.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.UsersIdMuteRequest.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.UsersLikesCreateRequest.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.UsersLikesCreateResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.UsersLikesCreateResponseData.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.UsersLikesDeleteResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.UsersMutingMutationResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.UsersMutingMutationResponseData.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.UsersRetweetsCreateRequest.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.UsersRetweetsCreateResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.UsersRetweetsCreateResponseData.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.UsersRetweetsDeleteResponse.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.Video.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.VideoAllOf.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.VideoAllOfNonPublicMetrics.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.VideoAllOfOrganicMetrics.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.VideoAllOfPromotedMetrics.CustomTypeAdapterFactory())
.registerTypeAdapterFactory(new com.twitter.clientlib.model.VideoAllOfPublicMetrics.CustomTypeAdapterFactory())
.create();
}
/**
* Get Gson.
*
* @return Gson
*/
public static Gson getGson() {
return gson;
}
/**
* Set Gson.
*
* @param gson Gson
*/
public static void setGson(Gson gson) {
JSON.gson = gson;
}
public static void setLenientOnJson(boolean lenientOnJson) {
isLenientOnJson = lenientOnJson;
}
/**
* Serialize the given Java object into JSON string.
*
* @param obj Object
* @return String representation of the JSON
*/
public static String serialize(Object obj) {
return gson.toJson(obj);
}
/**
* Deserialize the given JSON string to Java object.
*
* @param Type
* @param body The JSON string
* @param returnType The type to deserialize into
* @return The deserialized Java object
*/
@SuppressWarnings("unchecked")
public static T deserialize(String body, Type returnType) {
try {
if (isLenientOnJson) {
JsonReader jsonReader = new JsonReader(new StringReader(body));
// see https://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/stream/JsonReader.html#setLenient(boolean)
jsonReader.setLenient(true);
return gson.fromJson(jsonReader, returnType);
} else {
return gson.fromJson(body, returnType);
}
} catch (JsonParseException e) {
// Fallback processing when failed to parse JSON form response body:
// return the response body string directly for the String return type;
if (returnType.equals(String.class)) {
return (T) body;
} else {
throw (e);
}
}
}
/**
* Gson TypeAdapter for Byte Array type
*/
public static class ByteArrayAdapter extends TypeAdapter {
@Override
public void write(JsonWriter out, byte[] value) throws IOException {
if (value == null) {
out.nullValue();
} else {
out.value(ByteString.of(value).base64());
}
}
@Override
public byte[] read(JsonReader in) throws IOException {
switch (in.peek()) {
case NULL:
in.nextNull();
return null;
default:
String bytesAsBase64 = in.nextString();
ByteString byteString = ByteString.decodeBase64(bytesAsBase64);
return byteString.toByteArray();
}
}
}
/**
* Gson TypeAdapter for JSR310 OffsetDateTime type
*/
public static class OffsetDateTimeTypeAdapter extends TypeAdapter {
private DateTimeFormatter formatter;
public OffsetDateTimeTypeAdapter() {
this(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
}
public OffsetDateTimeTypeAdapter(DateTimeFormatter formatter) {
this.formatter = formatter;
}
public void setFormat(DateTimeFormatter dateFormat) {
this.formatter = dateFormat;
}
@Override
public void write(JsonWriter out, OffsetDateTime date) throws IOException {
if (date == null) {
out.nullValue();
} else {
out.value(formatter.format(date));
}
}
@Override
public OffsetDateTime read(JsonReader in) throws IOException {
switch (in.peek()) {
case NULL:
in.nextNull();
return null;
default:
String date = in.nextString();
if (date.endsWith("+0000")) {
date = date.substring(0, date.length()-5) + "Z";
}
return OffsetDateTime.parse(date, formatter);
}
}
}
/**
* Gson TypeAdapter for JSR310 LocalDate type
*/
public static class LocalDateTypeAdapter extends TypeAdapter {
private DateTimeFormatter formatter;
public LocalDateTypeAdapter() {
this(DateTimeFormatter.ISO_LOCAL_DATE);
}
public LocalDateTypeAdapter(DateTimeFormatter formatter) {
this.formatter = formatter;
}
public void setFormat(DateTimeFormatter dateFormat) {
this.formatter = dateFormat;
}
@Override
public void write(JsonWriter out, LocalDate date) throws IOException {
if (date == null) {
out.nullValue();
} else {
out.value(formatter.format(date));
}
}
@Override
public LocalDate read(JsonReader in) throws IOException {
switch (in.peek()) {
case NULL:
in.nextNull();
return null;
default:
String date = in.nextString();
return LocalDate.parse(date, formatter);
}
}
}
public static void setOffsetDateTimeFormat(DateTimeFormatter dateFormat) {
offsetDateTimeTypeAdapter.setFormat(dateFormat);
}
public static void setLocalDateFormat(DateTimeFormatter dateFormat) {
localDateTypeAdapter.setFormat(dateFormat);
}
/**
* Gson TypeAdapter for java.sql.Date type
* If the dateFormat is null, a simple "yyyy-MM-dd" format will be used
* (more efficient than SimpleDateFormat).
*/
public static class SqlDateTypeAdapter extends TypeAdapter {
private DateFormat dateFormat;
public SqlDateTypeAdapter() {}
public SqlDateTypeAdapter(DateFormat dateFormat) {
this.dateFormat = dateFormat;
}
public void setFormat(DateFormat dateFormat) {
this.dateFormat = dateFormat;
}
@Override
public void write(JsonWriter out, java.sql.Date date) throws IOException {
if (date == null) {
out.nullValue();
} else {
String value;
if (dateFormat != null) {
value = dateFormat.format(date);
} else {
value = date.toString();
}
out.value(value);
}
}
@Override
public java.sql.Date read(JsonReader in) throws IOException {
switch (in.peek()) {
case NULL:
in.nextNull();
return null;
default:
String date = in.nextString();
try {
if (dateFormat != null) {
return new java.sql.Date(dateFormat.parse(date).getTime());
}
return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime());
} catch (ParseException e) {
throw new JsonParseException(e);
}
}
}
}
/**
* Gson TypeAdapter for java.util.Date type
* If the dateFormat is null, ISO8601Utils will be used.
*/
public static class DateTypeAdapter extends TypeAdapter {
private DateFormat dateFormat;
public DateTypeAdapter() {}
public DateTypeAdapter(DateFormat dateFormat) {
this.dateFormat = dateFormat;
}
public void setFormat(DateFormat dateFormat) {
this.dateFormat = dateFormat;
}
@Override
public void write(JsonWriter out, Date date) throws IOException {
if (date == null) {
out.nullValue();
} else {
String value;
if (dateFormat != null) {
value = dateFormat.format(date);
} else {
value = ISO8601Utils.format(date, true);
}
out.value(value);
}
}
@Override
public Date read(JsonReader in) throws IOException {
try {
switch (in.peek()) {
case NULL:
in.nextNull();
return null;
default:
String date = in.nextString();
try {
if (dateFormat != null) {
return dateFormat.parse(date);
}
return ISO8601Utils.parse(date, new ParsePosition(0));
} catch (ParseException e) {
throw new JsonParseException(e);
}
}
} catch (IllegalArgumentException e) {
throw new JsonParseException(e);
}
}
}
public static void setDateFormat(DateFormat dateFormat) {
dateTypeAdapter.setFormat(dateFormat);
}
public static void setSqlDateFormat(DateFormat dateFormat) {
sqlDateTypeAdapter.setFormat(dateFormat);
}
}