com.logmein.gotowebinar.api.common.JsonUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gotowebinar-api Show documentation
Show all versions of gotowebinar-api Show documentation
Java SDK for the GoToWebinar REST API
/*
* © 2017 LogMeIn, Inc. All Rights Reserved.
* All rights reserved.
*
* This software is distributed under the terms and conditions of the
* LogMeIn SDK License Agreement. Please see file LICENSE for details.
*
* Auto-generated file.
*/
package com.logmein.gotowebinar.api.common;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.logmein.gotowebinar.api.model.ActivationState;
import com.logmein.gotowebinar.api.model.AudioType;
import com.logmein.gotowebinar.api.model.Product;
import com.logmein.gotowebinar.api.model.Registrant;
import com.logmein.gotowebinar.api.model.RegistrantDetailed;
import com.logmein.gotowebinar.api.model.RegistrationQuestion;
import com.logmein.gotowebinar.api.model.TollCountries;
import com.logmein.gotowebinar.api.model.TollFreeCountries;
import com.logmein.gotowebinar.api.model.UserSubscriptionState;
import com.logmein.gotowebinar.api.model.WebhookState;
import com.logmein.gotowebinar.api.model.Webinar;
import com.logmein.gotowebinar.api.model.WebinarByKey;
import com.logmein.gotowebinar.api.model.WebinarReqUpdate;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
public class JsonUtil {
public static ObjectMapper mapper;
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
static {
mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
mapper.setDateFormat(sdf);
mapper.registerModule(getModule());
mapper.setVisibility(PropertyAccessor.SETTER, JsonAutoDetect.Visibility.NONE);
mapper.setVisibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.NONE);
mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
private static Module getModule() {
SimpleModule module = new SimpleModule("BooleanAsString", new Version(1, 0, 0, null, null, null));
module.addDeserializer(Boolean.class, new JsonDeserializer() {
@Override
public Boolean deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
String value = jp.getValueAsString();
return "true".equalsIgnoreCase(value);
}
});
module.addDeserializer(ActivationState.class, new JsonDeserializer() {
@Override
public ActivationState deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
return getEnumFromString(ActivationState.class, jp.getValueAsString());
}
});
module.addDeserializer(AudioType.class, new JsonDeserializer() {
@Override
public AudioType deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
return getEnumFromString(AudioType.class, jp.getValueAsString());
}
});
module.addDeserializer(Product.class, new JsonDeserializer() {
@Override
public Product deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
return getEnumFromString(Product.class, jp.getValueAsString());
}
});
module.addDeserializer(Registrant.StatusEnum.class, new JsonDeserializer() {
@Override
public Registrant.StatusEnum deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
return getEnumFromString(Registrant.StatusEnum.class, jp.getValueAsString());
}
});
module.addDeserializer(RegistrantDetailed.StatusEnum.class, new JsonDeserializer() {
@Override
public RegistrantDetailed.StatusEnum deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
return getEnumFromString(RegistrantDetailed.StatusEnum.class, jp.getValueAsString());
}
});
module.addDeserializer(RegistrantDetailed.TypeEnum.class, new JsonDeserializer() {
@Override
public RegistrantDetailed.TypeEnum deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
return getEnumFromString(RegistrantDetailed.TypeEnum.class, jp.getValueAsString());
}
});
module.addDeserializer(RegistrationQuestion.TypeEnum.class, new JsonDeserializer() {
@Override
public RegistrationQuestion.TypeEnum deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
return getEnumFromString(RegistrationQuestion.TypeEnum.class, jp.getValueAsString());
}
});
module.addDeserializer(TollCountries.class, new JsonDeserializer() {
@Override
public TollCountries deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
return getEnumFromString(TollCountries.class, jp.getValueAsString());
}
});
module.addDeserializer(TollFreeCountries.class, new JsonDeserializer() {
@Override
public TollFreeCountries deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
return getEnumFromString(TollFreeCountries.class, jp.getValueAsString());
}
});
module.addDeserializer(UserSubscriptionState.class, new JsonDeserializer() {
@Override
public UserSubscriptionState deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
return getEnumFromString(UserSubscriptionState.class, jp.getValueAsString());
}
});
module.addDeserializer(WebhookState.class, new JsonDeserializer() {
@Override
public WebhookState deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
return getEnumFromString(WebhookState.class, jp.getValueAsString());
}
});
module.addDeserializer(Webinar.LocaleEnum.class, new JsonDeserializer() {
@Override
public Webinar.LocaleEnum deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
return getEnumFromString(Webinar.LocaleEnum.class, jp.getValueAsString());
}
});
module.addDeserializer(WebinarByKey.LocaleEnum.class, new JsonDeserializer() {
@Override
public WebinarByKey.LocaleEnum deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
return getEnumFromString(WebinarByKey.LocaleEnum.class, jp.getValueAsString());
}
});
module.addDeserializer(WebinarReqUpdate.LocaleEnum.class, new JsonDeserializer() {
@Override
public WebinarReqUpdate.LocaleEnum deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
return getEnumFromString(WebinarReqUpdate.LocaleEnum.class, jp.getValueAsString());
}
});
return module;
}
public static ObjectMapper getJsonMapper() {
return mapper;
}
public static > T getEnumFromString(Class c, String string) {
try {
return Enum.valueOf(c, string);
}
catch(NullPointerException ex) {
return null;
}
catch(IllegalArgumentException ex) {
return null;
}
}
public static String Stringify(Object obj) {
if (obj == null)
return "";
if (obj instanceof Date)
return sdf.format((Date)obj);
return obj.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy