urbanairship-core/src/main/java/com/urbanairship/iam/InAppMessage.java
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
    static InAppMessage fromJson(JsonValue jsonValue, @Source String defaultSource) throws JsonException {
        String type = jsonValue.optMap().opt(DISPLAY_TYPE_KEY).getString("");
        JsonValue content = jsonValue.optMap().opt(DISPLAY_CONTENT_KEY);


        String messageId = jsonValue.optMap().opt(MESSAGE_ID_KEY).getString();
        if (messageId == null || messageId.length() > MAX_ID_LENGTH) {
            throw new JsonException("Invalid message ID. Must be nonnull and less than or equal to " + MAX_ID_LENGTH + " characters.");
        }


        InAppMessage.Builder builder = InAppMessage.newBuilder()
                                                   .setId(messageId)
                                                   .setExtras(jsonValue.optMap().opt(EXTRA_KEY).optMap())
                                                   .setDisplayContent(type, content);


        // Source
        @Source String source = jsonValue.optMap().opt(SOURCE_KEY).getString(defaultSource);
        if (source != null) {
            builder.setSource(source);
        }

        // Actions
        if (jsonValue.optMap().containsKey(ACTIONS_KEY)) {
            JsonMap jsonMap = jsonValue.optMap().get(ACTIONS_KEY).getMap();
            if (jsonMap == null) {
                throw new JsonException("Actions must be a JSON object: " + jsonValue.optMap().opt(ACTIONS_KEY));
            }

            builder.setActions(jsonMap.getMap());
        }

        // Audience
        if (jsonValue.optMap().containsKey(AUDIENCE_KEY)) {
            builder.setAudience(Audience.parseJson(jsonValue.optMap().opt(AUDIENCE_KEY)));
        }

        // Campaigns
        if (jsonValue.optMap().containsKey(CAMPAIGNS_KEY)) {
            builder.setCampaigns(jsonValue.optMap().opt(CAMPAIGNS_KEY));
        }

        try {
            return builder.build();
        } catch (IllegalArgumentException e) {
            throw new JsonException("Invalid InAppMessage json.", e);
        }
    }
/**
     * Parses a json value.
     *
     * @param jsonValue The json value.
     * @param defaultSource The default source if its not set in the JSON.
     * @return The parsed InAppMessage.
     * @throws JsonException If the json is invalid.
     * @hide
     */
Parses a json value.
@param jsonValue The json value.
@param defaultSource The default source if its not set in the JSON.
@return The parsed InAppMessage.
@throws JsonException If the json is invalid.
@hide
Parses a json value . @param jsonValue The json value . @param defaultSource The default source if its not set in the JSON . @return The parsed InAppMessage . @throws JsonException If the json is invalid . @hide
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
    static InAppMessage fromJson(JsonValue jsonValue, @Source String defaultSource) throws JsonException {
        String type = jsonValue.optMap().opt(DISPLAY_TYPE_KEY).getString("");
        JsonValue content = jsonValue.optMap().opt(DISPLAY_CONTENT_KEY);
        String messageId = jsonValue.optMap().opt(MESSAGE_ID_KEY).getString();
        if (messageId == null || messageId.length() > MAX_ID_LENGTH) {
            throw new JsonException("Invalid message ID. Must be nonnull and less than or equal to " + MAX_ID_LENGTH + " characters.");
        }
        InAppMessage.Builder builder = InAppMessage.newBuilder()
                                                   .setId(messageId)
                                                   .setExtras(jsonValue.optMap().opt(EXTRA_KEY).optMap())
                                                   .setDisplayContent(type, content);
        @Source String source = jsonValue.optMap().opt(SOURCE_KEY).getString(defaultSource);
        if (source != null) {
            builder.setSource(source);
        }
        if (jsonValue.optMap().containsKey(ACTIONS_KEY)) {
            JsonMap jsonMap = jsonValue.optMap().get(ACTIONS_KEY).getMap();
            if (jsonMap == null) {
                throw new JsonException("Actions must be a JSON object: " + jsonValue.optMap().opt(ACTIONS_KEY));
            }
            builder.setActions(jsonMap.getMap());
        }
        if (jsonValue.optMap().containsKey(AUDIENCE_KEY)) {
            builder.setAudience(Audience.parseJson(jsonValue.optMap().opt(AUDIENCE_KEY)));
        }
        if (jsonValue.optMap().containsKey(CAMPAIGNS_KEY)) {
            builder.setCampaigns(jsonValue.optMap().opt(CAMPAIGNS_KEY));
        }
        try {
            return builder.build();
        } catch (IllegalArgumentException e) {
            throw new JsonException("Invalid InAppMessage json.", e);
        }
    }
@ RestrictTo ( RestrictTo . Scope . LIBRARY_GROUP ) static InAppMessage fromJson ( JsonValue jsonValue , @ Source String defaultSource ) throws JsonException { String type = jsonValue . optMap ( ) . opt ( DISPLAY_TYPE_KEY ) . getString ( "" ) ; JsonValue content = jsonValue . optMap ( ) . opt ( DISPLAY_CONTENT_KEY ) ; String messageId = jsonValue . optMap ( ) . opt ( MESSAGE_ID_KEY ) . getString ( ) ; if ( messageId == null || messageId . length ( ) > MAX_ID_LENGTH ) { throw new JsonException ( "Invalid message ID. Must be nonnull and less than or equal to " + MAX_ID_LENGTH + " characters." ) ; } InAppMessage . Builder builder = InAppMessage . newBuilder ( ) . setId ( messageId ) . setExtras ( jsonValue . optMap ( ) . opt ( EXTRA_KEY ) . optMap ( ) ) . setDisplayContent ( type , content ) ; @ Source String source = jsonValue . optMap ( ) . opt ( SOURCE_KEY ) . getString ( defaultSource ) ; if ( source != null ) { builder . setSource ( source ) ; } if ( jsonValue . optMap ( ) . containsKey ( ACTIONS_KEY ) ) { JsonMap jsonMap = jsonValue . optMap ( ) . get ( ACTIONS_KEY ) . getMap ( ) ; if ( jsonMap == null ) { throw new JsonException ( "Actions must be a JSON object: " + jsonValue . optMap ( ) . opt ( ACTIONS_KEY ) ) ; } builder . setActions ( jsonMap . getMap ( ) ) ; } if ( jsonValue . optMap ( ) . containsKey ( AUDIENCE_KEY ) ) { builder . setAudience ( Audience . parseJson ( jsonValue . optMap ( ) . opt ( AUDIENCE_KEY ) ) ) ; } if ( jsonValue . optMap ( ) . containsKey ( CAMPAIGNS_KEY ) ) { builder . setCampaigns ( jsonValue . optMap ( ) . opt ( CAMPAIGNS_KEY ) ) ; } try { return builder . build ( ) ; } catch ( IllegalArgumentException e ) { throw new JsonException ( "Invalid InAppMessage json." , e ) ; } }
Parses a json value.
Parses a json value .
// Source // Actions // Audience // Campaigns