ChannelRegistrationPayload implements JsonSerializable { static ChannelRegistrationPayload fromJson(JsonValue value) throws JsonException { JsonMap jsonMap = value.optMap(); JsonMap channelJson = jsonMap.opt(CHANNEL_KEY).optMap(); JsonMap identityHints = jsonMap.opt(IDENTITY_HINTS_KEY).optMap(); if (channelJson.isEmpty() && identityHints.isEmpty()) { throw new JsonException("Invalid channel payload: " + value); } Set<String> tags = new HashSet<>(); for (JsonValue tag : channelJson.opt(TAGS_KEY).optList()) { if (tag.isString()) { tags.add(tag.getString()); } else { throw new JsonException("Invalid tag: " + tag); } } Boolean locationSettings = null; Integer apiVersion = null; if (channelJson.containsKey(LOCATION_SETTINGS_KEY)) { locationSettings = channelJson.opt(LOCATION_SETTINGS_KEY).getBoolean(false); } if (channelJson.containsKey(API_VERSION_KEY)) { apiVersion = channelJson.opt(API_VERSION_KEY).getInt(-1); } String deliveryType = channelJson.opt(ANDROID_EXTRAS_KEY).optMap().opt(ANDROID_DELIVERY_TYPE).getString(); return new Builder().setOptIn(channelJson.opt(OPT_IN_KEY).getBoolean(false)) .setBackgroundEnabled(channelJson.opt(BACKGROUND_ENABLED_KEY).getBoolean(false)) .setDeviceType(channelJson.opt(DEVICE_TYPE_KEY).getString()) .setPushAddress(channelJson.opt(PUSH_ADDRESS_KEY).getString()) .setLanguage(channelJson.opt(LANGUAGE_KEY).getString()) .setCountry(channelJson.opt(COUNTRY_KEY).getString()) .setTimezone(channelJson.opt(TIMEZONE_KEY).getString()) .setTags(channelJson.opt(SET_TAGS_KEY).getBoolean(false), tags) .setUserId(identityHints.opt(USER_ID_KEY).getString()) .setApid(identityHints.opt(APID_KEY).getString()) .setAccengageDeviceId(identityHints.opt(ACCENGAGE_DEVICE_ID).getString()) .setLocationSettings(locationSettings) .setAppVersion(channelJson.opt(APP_VERSION_KEY).getString()) .setSdkVersion(channelJson.opt(SDK_VERSION_KEY).getString()) .setDeviceModel(channelJson.opt(DEVICE_MODEL_KEY).getString()) .setApiVersion(apiVersion) .setCarrier(channelJson.opt(CARRIER_KEY).getString()) .setDeliveryType(deliveryType) .setNamedUserId(channelJson.opt(NAMED_USER_ID_KEY).getString()) .build(); } private  ChannelRegistrationPayload(Builder builder); @NonNull ChannelRegistrationPayload minimizedPayload(@Nullable ChannelRegistrationPayload last); @NonNull @Override JsonValue toJsonValue(); @NonNull @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); @NonNull
    static final String ANDROID_DEVICE_TYPE; @NonNull
    static final String AMAZON_DEVICE_TYPE; final boolean optIn; final boolean backgroundEnabled; final String deviceType; final String pushAddress; final boolean setTags; final Set<String> tags; final String userId; final String apid; final String timezone; final String language; final String country; final Boolean locationSettings; final String appVersion; final String sdkVersion; final String deviceModel; final Integer apiVersion; final String carrier; final String accengageDeviceId; final String deliveryType; final String namedUserId; }
@Test(expected = JsonException.class) public void testCreateFromEmptyJSON() throws JsonException { ChannelRegistrationPayload.fromJson(JsonValue.NULL); }