Example usage for com.google.gson JsonNull INSTANCE

List of usage examples for com.google.gson JsonNull INSTANCE

Introduction

In this page you can find the example usage for com.google.gson JsonNull INSTANCE.

Prototype

JsonNull INSTANCE

To view the source code for com.google.gson JsonNull INSTANCE.

Click Source Link

Document

singleton for JsonNull

Usage

From source file:org.jetbrains.idea.maven.indices.BintrayIndexer.java

License:Open Source License

protected void fetchMavenIds(HttpRequests.Request request, MavenIndicesProcessor processor) throws IOException {
    try (InputStream in = request.getInputStream()) {
        JsonElement element = new JsonParser().parse(new InputStreamReader(in));
        JsonArray array = element.getAsJsonArray();
        if (array == null) {
            throw new IOException("Unexpected response format, JSON array expected from " + request.getURL());
        }/*from w w w.  j av a2  s.  c o m*/

        List<IndexedMavenId> mavenIds = new ArrayList<>();
        for (JsonElement el : array) {
            JsonObject jo = el.getAsJsonObject();
            JsonArray systemIds = jo.getAsJsonArray("system_ids");
            JsonArray versions = jo.getAsJsonArray("versions");
            JsonElement desc = jo.get("desc");
            String description = desc == null || desc == JsonNull.INSTANCE ? null : desc.getAsString();

            if (systemIds != null && versions != null) {
                for (JsonElement systemId : systemIds) {
                    String groupAndArtifactId = systemId.getAsString();
                    List<String> list = split(groupAndArtifactId, ":");
                    if (list.size() != 2) {
                        continue;
                    }

                    String groupId = list.get(0);
                    String artifactId = list.get(1);
                    for (JsonElement version : versions) {
                        mavenIds.add(new IndexedMavenId(groupId, artifactId, version.getAsString(), null,
                                description));
                    }
                }
            }
        }
        synchronized (this) {
            processor.processArtifacts(mavenIds);
        }
    }
}

From source file:org.jfvclient.EmptyFVRpcRequest.java

License:Apache License

/**
 * Create a new EmptyFVRpcRequest with the given type and id.
 *
 * @see NoParamType//from   ww  w . j a va2  s.  c  o m
 * @param t
 *            the method
 * @param id
 *            a request ID. Must not be null.
 */
public EmptyFVRpcRequest(NoParamType t, String id) {
    super();
    switch (t) {
    case list_slices:
        setMethod("list-slices");
        break;
    case list_version:
        setMethod("list-version");
        break;
    case list_datapaths:
        setMethod("list-datapaths");
        break;
    case list_links:
        setMethod("list-links");
        break;
    case list_fv_health:
        setMethod("list-fv-health");
        break;
    case save_config:
        setMethod("save-config");
        break;
    default:
        throw new AssertionError(t.name());
    }
    setId(id);
    setParams(JsonNull.INSTANCE);
}

From source file:org.jsfr.json.provider.GsonProvider.java

License:Open Source License

@Override
public JsonElement primitiveNull() {
    return JsonNull.INSTANCE;
}

From source file:org.jsonbuilder.implementations.gson.GsonNullNode.java

License:Apache License

public GsonNullNode() {
    this.jsonNull = JsonNull.INSTANCE;
}

From source file:org.lanternpowered.server.script.function.action.json.EmptyActionJsonSerializer.java

License:MIT License

@Override
public JsonElement serialize(EmptyAction src, Type typeOfSrc, JsonSerializationContext context) {
    return JsonNull.INSTANCE;
}

From source file:org.lanternpowered.server.world.weather.WeatherBuilderJsonSerializer.java

License:MIT License

@Override
public WeatherBuilder deserialize(JsonElement element, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    final JsonObject json = element.getAsJsonObject();
    final Set<String> aliases;
    if (json.has("aliases")) {
        aliases = ImmutableSet.copyOf((String[]) context.deserialize(json.get("aliases"), String[].class));
    } else {//ww w.  j  a  v  a 2 s.com
        aliases = ImmutableSet.of();
    }
    final OptionValueMap options;
    if (json.has("options")) {
        options = context.deserialize(json.get("options"), UnmodifiableOptionValueMap.class);
    } else {
        options = new UnmodifiableOptionValueMap(new SimpleOptionValueMap());
    }
    final Action action = context.deserialize(json.has("action") ? json.get("action") : JsonNull.INSTANCE,
            Action.class);
    final WeatherBuilder builder = LanternWeather.builder().action(action).aliases(aliases).options(options);
    if (json.has("name")) {
        builder.name(json.get("name").getAsString());
    }
    if (json.has("weight")) {
        builder.weight(json.get("weight").getAsDouble());
    }
    if (json.has("duration")) {
        builder.duration(context.deserialize(json.get("duration"), IntValueProvider.class));
    }
    return builder;
}

From source file:org.matrix.androidsdk.adapters.MessagesAdapter.java

License:Apache License

/**
 * Common view management.//from  w  w w  .j av  a  2  s  .  c  o m
 *
 * @param position    the item position.
 * @param convertView the row view
 * @param subView     the message content view
 * @param msgType     the message type
 * @return true if the view is merged.
 */
protected boolean manageSubView(final int position, View convertView, View subView, int msgType) {
    MessageRow row = getItem(position);
    Event event = row.getEvent();
    RoomState roomState = row.getRoomState();

    convertView.setClickable(false);

    boolean isAvatarOnRightSide = isAvatarDisplayedOnRightSide(event);

    // isMergedView -> the message is going to be merged with the previous one
    // willBeMerged ->tell if a message separator must be displayed
    boolean isMergedView = false;
    boolean willBeMerged = false;

    if (!mIsSearchMode) {

        if ((position > 0) && isMergeableEvent(event)) {
            MessageRow prevRow = getItem(position - 1);
            isMergedView = TextUtils.equals(prevRow.getEvent().getSender(), event.getSender());
        }

        // not the last message
        if ((position + 1) < this.getCount()) {
            MessageRow nextRow = getItem(position + 1);

            if (isMergeableEvent(event) || isMergeableEvent(nextRow.getEvent())) {
                // the message will be merged if the message senders are not the same
                // or the message is an avatar / displayname update.
                willBeMerged = TextUtils.equals(nextRow.getEvent().getSender(), event.getSender())
                        && isMergeableEvent(nextRow.getEvent());
            }
        }
    }

    // inherited class custom behaviour
    isMergedView = mergeView(event, position, isMergedView);

    View leftTsTextLayout = convertView.findViewById(R.id.message_timestamp_layout_left);
    View rightTsTextLayout = convertView.findViewById(R.id.message_timestamp_layout_right);

    // manage sender text
    TextView textView = (TextView) convertView.findViewById(R.id.messagesAdapter_sender);
    if (null != textView) {
        if (null == rightTsTextLayout) {
            textView.setVisibility(View.VISIBLE);

            if (isMergedView) {
                textView.setText("");
            } else {
                textView.setText(getUserDisplayName(event.getSender(), row.getRoomState()));
            }
        } else if (isMergedView || isAvatarOnRightSide) {
            textView.setVisibility(View.GONE);
        } else {
            String eventType = event.getType();

            // theses events are managed like notice ones
            // but they are dedicated behaviour i.e the sender must not be displayed
            if (event.isCallEvent() || Event.EVENT_TYPE_STATE_ROOM_TOPIC.equals(eventType)
                    || Event.EVENT_TYPE_STATE_ROOM_MEMBER.equals(eventType)
                    || Event.EVENT_TYPE_STATE_ROOM_NAME.equals(eventType)
                    || Event.EVENT_TYPE_STATE_ROOM_THIRD_PARTY_INVITE.equals(eventType)) {
                textView.setVisibility(View.GONE);
            } else {
                textView.setVisibility(View.VISIBLE);
                textView.setText(getUserDisplayName(event.getSender(), row.getRoomState()));
            }
        }

        final String fSenderId = event.getSender();
        final String fDisplayName = (null == textView.getText()) ? "" : textView.getText().toString();

        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != mMessagesAdapterEventsListener) {
                    mMessagesAdapterEventsListener.onSenderNameClick(fSenderId, fDisplayName);
                }
            }
        });
    }

    TextView tsTextView;
    TextView leftTsTextView = null;
    TextView rightTsTextView = null;

    if (null != leftTsTextLayout) {
        leftTsTextView = (TextView) leftTsTextLayout.findViewById(R.id.messagesAdapter_timestamp);
    }

    if (null != rightTsTextLayout) {
        rightTsTextView = (TextView) rightTsTextLayout.findViewById(R.id.messagesAdapter_timestamp);
    }

    if (isAvatarOnRightSide) {
        tsTextView = leftTsTextView;
        if (null != rightTsTextView) {
            rightTsTextView.setVisibility(View.GONE);
        }
    } else {
        tsTextView = rightTsTextView;
        if (null != leftTsTextView) {
            leftTsTextView.setVisibility(View.GONE);
        }
    }

    if (null != tsTextView) {
        String timeStamp = getFormattedTimestamp(event);

        if (TextUtils.isEmpty(timeStamp)) {
            tsTextView.setVisibility(View.GONE);
        } else {
            tsTextView.setVisibility(View.VISIBLE);
            tsTextView.setText(timeStamp);

            tsTextView.setGravity(isAvatarOnRightSide ? Gravity.LEFT : Gravity.RIGHT);
        }

        if (row.getEvent().isUndeliverable() || row.getEvent().isUnkownDevice()) {
            tsTextView.setTextColor(mNotSentMessageTextColor);
        } else {
            tsTextView.setTextColor(mContext.getResources().getColor(R.color.chat_gray_text));
        }
    }

    // read receipts
    LinearLayout leftReceiversLayout = null;
    LinearLayout rightReceiversLayout = null;

    if (null != leftTsTextLayout) {
        leftReceiversLayout = (LinearLayout) leftTsTextLayout.findViewById(R.id.messagesAdapter_receivers_list);

        if (null != leftReceiversLayout) {
            leftReceiversLayout.setVisibility(isAvatarOnRightSide ? View.VISIBLE : View.GONE);
        }
    }

    if (null != rightTsTextLayout) {
        rightReceiversLayout = (LinearLayout) rightTsTextLayout
                .findViewById(R.id.messagesAdapter_receivers_list);

        if (null != rightReceiversLayout) {
            rightReceiversLayout.setVisibility(isAvatarOnRightSide ? View.GONE : View.VISIBLE);
        }
    }

    refreshReceiverLayout(isAvatarOnRightSide ? leftReceiversLayout : rightReceiversLayout, isAvatarOnRightSide,
            event.eventId, roomState);

    // Sender avatar
    RoomMember sender = null;

    if (null != roomState) {
        sender = roomState.getMember(event.getSender());
    }

    View avatarLeftView = convertView.findViewById(R.id.messagesAdapter_roundAvatar_left);
    View avatarRightView = convertView.findViewById(R.id.messagesAdapter_roundAvatar_right);
    View avatarLayoutView;

    if (isAvatarOnRightSide) {
        avatarLayoutView = avatarRightView;

        if (null != avatarLeftView) {
            avatarLeftView.setVisibility(View.GONE);
        }
    } else {
        avatarLayoutView = avatarLeftView;

        if (null != avatarRightView) {
            avatarRightView.setVisibility(View.GONE);
        }

        if (null != avatarLeftView) {
            final String userId = event.getSender();

            avatarLeftView.setClickable(true);

            avatarLeftView.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    if (null != mMessagesAdapterEventsListener) {
                        return mMessagesAdapterEventsListener.onAvatarLongClick(userId);
                    } else {
                        return false;
                    }
                }
            });

            // click on the avatar opens the details page
            avatarLeftView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (null != mMessagesAdapterEventsListener) {
                        mMessagesAdapterEventsListener.onAvatarClick(userId);
                    }
                }
            });
        }
    }

    if (null != avatarLayoutView) {
        ImageView avatarImageView = (ImageView) avatarLayoutView.findViewById(R.id.avatar_img);
        ImageView presenceView = (ImageView) avatarLayoutView.findViewById(R.id.imageView_presenceRing);

        final String userId = event.getSender();
        refreshPresenceRing(presenceView, userId);

        if (isMergedView) {
            avatarLayoutView.setVisibility(View.GONE);
        } else {
            avatarLayoutView.setVisibility(View.VISIBLE);
            avatarImageView.setTag(null);

            String url = null;
            String displayName = null;

            // Check whether this avatar url is updated by the current event (This happens in case of new joined member)
            JsonObject msgContent = event.getContentAsJsonObject();

            if (msgContent.has("avatar_url")) {
                url = msgContent.get("avatar_url") == JsonNull.INSTANCE ? null
                        : msgContent.get("avatar_url").getAsString();
            }

            if (msgContent.has("membership")) {
                String memberShip = msgContent.get("membership") == JsonNull.INSTANCE ? null
                        : msgContent.get("membership").getAsString();

                // the avatar url is the invited one not the inviter one.
                if (TextUtils.equals(memberShip, RoomMember.MEMBERSHIP_INVITE)) {
                    url = null;

                    if (null != sender) {
                        url = sender.avatarUrl;
                    }
                }

                if (TextUtils.equals(memberShip, RoomMember.MEMBERSHIP_JOIN)) {
                    // in some cases, the displayname cannot be retrieved because the user member joined the room with this event
                    // without being invited (a public room for example)
                    if (msgContent.has("displayname")) {
                        displayName = msgContent.get("displayname") == JsonNull.INSTANCE ? null
                                : msgContent.get("displayname").getAsString();
                    }
                }
            }

            loadMemberAvatar(avatarImageView, sender, userId, displayName, url);

            // display the typing icon when required
            setTypingVisibility(avatarLayoutView,
                    (!isAvatarOnRightSide && (mTypingUsers.indexOf(event.getSender()) >= 0)) ? View.VISIBLE
                            : View.GONE);
        }
    }

    // if the messages are merged
    // the thumbnail is hidden
    // and the subview must be moved to be aligned with the previous body
    View bodyLayoutView = convertView.findViewById(R.id.messagesAdapter_body_layout);
    ViewGroup.MarginLayoutParams bodyLayout = (ViewGroup.MarginLayoutParams) bodyLayoutView.getLayoutParams();
    FrameLayout.LayoutParams subViewLinearLayout = (FrameLayout.LayoutParams) subView.getLayoutParams();

    View view = convertView.findViewById(R.id.messagesAdapter_roundAvatar_left);
    ViewGroup.LayoutParams avatarLayout = view.getLayoutParams();

    if (!isAvatarOnRightSide) {
        subViewLinearLayout.gravity = Gravity.LEFT | Gravity.CENTER_VERTICAL;

        if (isMergedView) {
            bodyLayout.setMargins(avatarLayout.width, bodyLayout.topMargin, 4, bodyLayout.bottomMargin);

        } else {
            bodyLayout.setMargins(4, bodyLayout.topMargin, 4, bodyLayout.bottomMargin);
        }
        subView.setLayoutParams(bodyLayout);
    } else {
        subViewLinearLayout.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL;

        if (isMergedView) {
            bodyLayout.setMargins(4, bodyLayout.topMargin, avatarLayout.width, bodyLayout.bottomMargin);
        } else {
            bodyLayout.setMargins(4, bodyLayout.topMargin, 4, bodyLayout.bottomMargin);
        }
    }

    bodyLayoutView.setLayoutParams(bodyLayout);
    subView.setLayoutParams(subViewLinearLayout);

    view = convertView.findViewById(R.id.messagesAdapter_message_separator);

    if (null != view) {
        view.setVisibility((willBeMerged || ((position + 1) == this.getCount())) ? View.GONE : View.VISIBLE);
    }

    convertView.setClickable(true);

    // click on the avatar opens the details page
    convertView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (null != mMessagesAdapterEventsListener) {
                mMessagesAdapterEventsListener.onRowClick(position);
            }
        }
    });

    // click on the avatar opens the details page
    convertView.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            if (null != mMessagesAdapterEventsListener) {
                return mMessagesAdapterEventsListener.onRowLongClick(position);
            }

            return false;
        }
    });

    return isMergedView;
}

From source file:org.mitre.openid.connect.view.JSONIdTokenView.java

License:Apache License

protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    Gson gson = new GsonBuilder().setExclusionStrategies(new ExclusionStrategy() {

        public boolean shouldSkipField(FieldAttributes f) {

            return false;
        }//from   w  w w. j a v a  2 s.co m

        public boolean shouldSkipClass(Class<?> clazz) {
            // skip the JPA binding wrapper
            if (clazz.equals(BeanPropertyBindingResult.class)) {
                return true;
            }
            return false;
        }

    }).registerTypeHierarchyAdapter(ClaimSet.class, new JsonSerializer<ClaimSet>() {
        @Override
        public JsonElement serialize(ClaimSet src, Type typeOfSrc, JsonSerializationContext context) {
            if (src != null) {
                return src.getAsJsonObject();
            } else {
                return JsonNull.INSTANCE;
            }
        }
    }).create();

    response.setContentType("application/json");

    Writer out = response.getWriter();

    Object obj = model.get("entity");
    if (obj == null) {
        obj = model;
    }

    gson.toJson(obj, out);
}

From source file:org.mitre.util.JsonUtils.java

License:Apache License

/**
 * Translate a set of strings to a JSON array, optionally preserving the empty array. Otherwise (default) empty array is returned as null.
 * @param value//from   w  w  w  .jav a  2  s .c  o m
 * @param preserveEmpty
 * @return
 */
public static JsonElement getAsArray(Set<String> value, boolean preserveEmpty) {
    if (!preserveEmpty && value != null && value.isEmpty()) {
        // if we're not preserving empty arrays and the value is empty, return null
        return JsonNull.INSTANCE;
    } else {
        return gson.toJsonTree(value, new TypeToken<Set<String>>() {
        }.getType());
    }
}

From source file:org.mobicents.servlet.restcomm.http.converter.AbstractConverter.java

License:Open Source License

protected void writeAccountSid(final Sid accountSid, final JsonObject object) {
    if (accountSid != null) {
        object.addProperty("account_sid", accountSid.toString());
    } else {//from  www  .j  ava 2 s  .  c o m
        object.add("account_sid", JsonNull.INSTANCE);
    }
}