Example usage for com.google.gson.stream JsonReader beginObject

List of usage examples for com.google.gson.stream JsonReader beginObject

Introduction

In this page you can find the example usage for com.google.gson.stream JsonReader beginObject.

Prototype

public void beginObject() throws IOException 

Source Link

Document

Consumes the next token from the JSON stream and asserts that it is the beginning of a new object.

Usage

From source file:es.chatclient.server.messages.adapters.ConversDataMessageTypeAdapter.java

@Override
public ConversDataMessage read(JsonReader in) throws IOException {

    final ConversDataMessage conversDate = new ConversDataMessage();
    final List<ConverData> converDataList = new ArrayList();

    in.beginObject();

    in.nextName();/*from  w  w  w .  j av  a2 s  .c  o m*/

    in.beginArray();

    while (in.hasNext()) {
        in.beginObject();
        final ConverData converData = new ConverData();

        while (in.hasNext()) {
            switch (in.nextName()) {

            case "converID":
                converData.setConverID(in.nextString());

                break;

            case "converName":
                converData.setConverName(in.nextString());
                break;

            case "arrayMessages":

                final List<Message> msgList = new ArrayList();

                in.beginArray();
                while (in.hasNext()) {
                    in.beginObject();
                    final Message msg = new Message();

                    while (in.hasNext()) {
                        switch (in.nextName()) {
                        case "msgID":
                            msg.setMsgID(in.nextString());
                            break;

                        case "msgType":
                            msg.setMsgType(in.nextString());
                            break;

                        case "msgText":
                            msg.setMsgText(in.nextString());
                            break;

                        case "msgDate":
                            msg.setMsgDate(in.nextString());
                            break;

                        case "clientId":
                            msg.setClientId(in.nextString());
                            break;

                        case "converId":
                            msg.setConverId(in.nextString());
                            break;

                        case "userNick":
                            msg.setUserNick(in.nextString());
                            break;

                        } //fin switch

                    }

                    msgList.add(msg);
                    in.endObject();

                }

                in.endArray();

                converData.setConverMessages(msgList);

                break;

            default:

                break;

            }

        }

        converDataList.add(converData);
        in.endObject();

    }

    in.endArray();
    conversDate.setConverDataArray(converDataList);

    in.endObject();

    return conversDate;

}

From source file:es.chatclient.server.messages.adapters.RequestMessageTypeAdapter.java

@Override
public RequestMessage read(JsonReader in) throws IOException {

    final RequestMessage loginRequest = new RequestMessage();

    in.beginObject();

    in.nextName();//from w w  w .ja  v  a  2s  . c om
    loginRequest.setUserName(in.nextString());

    in.nextName();
    loginRequest.setUserNick(in.nextString());

    in.nextName();
    loginRequest.setUserPassword(in.nextString());

    in.nextName();
    loginRequest.setUserEmail(in.nextString());

    in.nextName();
    loginRequest.setRequestType(in.nextInt());

    in.endObject();

    return loginRequest;

}

From source file:es.chatclient.server.messages.adapters.ServerMessageTypeAdapter.java

@Override
public Message read(JsonReader in) throws IOException {

    final Message msg = new Message();

    in.beginObject();

    while (in.hasNext()) {
        switch (in.nextName()) {
        case "msgID":
            msg.setMsgID(in.nextString());
            break;

        case "msgType":
            msg.setMsgType(in.nextString());
            break;

        case "msgText":
            msg.setMsgText(in.nextString());
            break;

        case "msgDate":
            msg.setMsgDate(in.nextString());
            break;

        case "clientId":
            msg.setClientId(in.nextString());
            break;

        case "converId":
            msg.setConverId(in.nextString());
            break;

        case "userNick":
            msg.setUserNick(in.nextString());
            break;

        } //fin switch

    }/*from w ww . j ava2 s.c om*/

    in.endObject();

    return msg;

}

From source file:eu.crushedpixel.littlstar.api.gson.ResponseWrapperTypeAdapter.java

License:Apache License

@Override
public ResponseWrapper<T> read(JsonReader in) throws IOException {
    Meta meta = null;//from ww  w .  j  a  v a  2  s . co m
    Pagination pagination = null;
    T data = null;

    in.beginObject();

    while (in.hasNext()) { //iterate over all array entries
        String key = in.nextName();

        if ("meta".equals(key)) {
            meta = LittlstarApiClient.GSON.fromJson(in, Meta.class);

        } else if ("pagination".equals(key)) {
            pagination = LittlstarApiClient.GSON.fromJson(in, Pagination.class);

        } else if ("data".equals(key)) {
            data = LittlstarApiClient.GSON.fromJson(in, wrappedClass);
        }
    }

    in.endObject();

    return new ResponseWrapper<T>(meta, pagination, data);
}

From source file:io.bouquet.v4.GsonFactory.java

License:Apache License

@Override
public ApiException read(JsonReader in) throws IOException {
    in.beginObject();
    String message = null;/*  w  w  w .  j  a  v  a 2 s  .c o  m*/
    int code = 0;
    String redirectURL = null;
    String clientId = null;
    String type = null;
    while (in.hasNext()) {
        switch (in.nextName()) {
        case "code":
            code = in.nextInt();
            break;
        case "type":
            type = in.nextString();
        case "error":
            message = in.nextString();
        case "redirectURL":
            redirectURL = in.nextString();
        case "clientId":
            clientId = in.nextString();
        }
    }
    ApiException ae = new ApiException(code, message);
    ae.setType(type);
    ae.setRedirectURL(redirectURL);
    ae.setClientId(clientId);
    return ae;
}

From source file:io.github.rcarlosdasilva.weixin.core.json.adapter.OpenPlatformAuthGetLicenseInformationResponseTypeAdapter.java

@Override
public OpenPlatformAuthGetLicenseInformationResponse read(JsonReader in) throws IOException {
    OpenPlatformAuthGetLicenseInformationResponse model = new OpenPlatformAuthGetLicenseInformationResponse();

    in.beginObject();
    while (in.hasNext()) {
        String key = in.nextName();
        switch (key) {
        case Convention.OPEN_PLATFORM_AUTH_LICENSED_INFORMATION_KEY:
            readLicensedAccessToken(in, model);
            break;
        case Convention.OPEN_PLATFORM_AUTH_LICENSOR_INFORMATION_KEY:
            readLicensorInformation(in, model);
            break;
        case Convention.OPEN_PLATFORM_AUTH_LICENSED_ACCESS_TOKEN_KEY:
            model.getLicensedAccessToken().setAccessToken(in.nextString());
            break;
        case Convention.OPEN_PLATFORM_AUTH_LICENSED_ACCESS_TOKEN_EXPIRES_IN_KEY:
            model.getLicensedAccessToken().setExpiresIn(in.nextInt());
            break;
        case Convention.OPEN_PLATFORM_AUTH_LICENSED_REFRESH_TOKEN_KEY:
            model.getLicensedAccessToken().setRefreshToken(in.nextString());
            break;
        default://from   ww w.j a  v a2s . c o m
            if (in.hasNext()) {
                String value = in.nextString();
                logger.warn(LOG_UNKNOWN_JSON_KEY, key, value);
            }
        }
    }

    in.endObject();

    return model;
}

From source file:io.github.rcarlosdasilva.weixin.core.json.adapter.OpenPlatformAuthGetLicenseInformationResponseTypeAdapter.java

private void readLicensedAccessToken(JsonReader in, OpenPlatformAuthGetLicenseInformationResponse model)
        throws IOException {
    LicensingInformation licensingInformation = new LicensingInformation();
    in.beginObject();

    while (in.hasNext()) {
        String key = in.nextName();
        switch (key) {
        case Convention.OPEN_PLATFORM_AUTH_LICENSED_APPID_ALIAS_KEY:
        case Convention.OPEN_PLATFORM_AUTH_LICENSED_APPID_KEY:
            licensingInformation.setAppId(in.nextString());
            break;
        case Convention.OPEN_PLATFORM_AUTH_LICENSED_ACCESS_TOKEN_KEY:
            model.getLicensedAccessToken().setAccessToken(in.nextString());
            break;
        case Convention.OPEN_PLATFORM_AUTH_LICENSED_ACCESS_TOKEN_EXPIRES_IN_KEY:
            model.getLicensedAccessToken().setExpiresIn(in.nextInt());
            break;
        case Convention.OPEN_PLATFORM_AUTH_LICENSED_REFRESH_TOKEN_KEY:
            model.getLicensedAccessToken().setRefreshToken(in.nextString());
            break;
        case Convention.OPEN_PLATFORM_AUTH_LICENSED_FUNCTIONS_INFO_KEY: {
            in.beginArray();/*from  w w w  .  ja  v a2 s .c om*/

            while (in.hasNext()) {
                in.beginObject();
                in.nextName();
                in.beginObject();
                in.nextName();
                licensingInformation.addLicencedFunction(in.nextInt());
                in.endObject();
                in.endObject();
            }

            in.endArray();
            break;
        }
        default:
            if (in.hasNext()) {
                String value = in.nextString();
                logger.warn(LOG_UNKNOWN_JSON_KEY, key, value);
            }
        }
    }

    in.endObject();
    model.setLicensingInformation(licensingInformation);
}

From source file:io.github.rcarlosdasilva.weixin.core.json.adapter.OpenPlatformAuthGetLicenseInformationResponseTypeAdapter.java

private void readLicensorInformation(JsonReader in, OpenPlatformAuthGetLicenseInformationResponse model)
        throws IOException {
    LicensorInfromation licensorInfromation = new LicensorInfromation();
    in.beginObject();

    while (in.hasNext()) {
        String key = in.nextName();
        switch (key) {
        case Convention.OPEN_PLATFORM_AUTH_LICENSOR_NICKNAME_KEY:
            licensorInfromation.setNickName(in.nextString());
            break;
        case Convention.OPEN_PLATFORM_AUTH_LICENSOR_LOGO_KEY:
            licensorInfromation.setLogo(in.nextString());
            break;
        case Convention.OPEN_PLATFORM_AUTH_LICENSOR_ACCOUNT_TYPE_KEY: {
            in.beginObject();/*  www  .j a  va 2  s . c  om*/
            in.nextName();
            licensorInfromation.setAccountType(in.nextInt());
            in.endObject();
            break;
        }
        case Convention.OPEN_PLATFORM_AUTH_LICENSOR_ACCOUNT_VERIFIED_TYPE_KEY: {
            in.beginObject();
            in.nextName();
            licensorInfromation.setAccountVerifiedType(in.nextInt());
            in.endObject();
            break;
        }
        case Convention.OPEN_PLATFORM_AUTH_LICENSOR_MPID_KEY:
            licensorInfromation.setMpId(in.nextString());
            break;
        case Convention.OPEN_PLATFORM_AUTH_LICENSOR_PRINCIPAL_NAME_KEY:
            licensorInfromation.setPrincipalName(in.nextString());
            break;
        case Convention.OPEN_PLATFORM_AUTH_LICENSOR_ACCOUNT_NAME_KEY:
            licensorInfromation.setAccountName(in.nextString());
            break;
        case Convention.OPEN_PLATFORM_AUTH_LICENSOR_QRCODE_URL_KEY:
            licensorInfromation.setQrCodeUrl(in.nextString());
            break;
        case Convention.OPEN_PLATFORM_AUTH_LICENSOR_BUSINESS_INFO_KEY:
            readBusinessInfo(in, licensorInfromation);
            break;
        default:
            if (in.hasNext()) {
                String value = in.nextString();
                logger.warn(LOG_UNKNOWN_JSON_KEY, key, value);
            }
        }
    }

    in.endObject();
    model.setLicensorInfromation(licensorInfromation);
}

From source file:io.github.rcarlosdasilva.weixin.core.json.adapter.OpenPlatformAuthGetLicenseInformationResponseTypeAdapter.java

private void readBusinessInfo(JsonReader in, LicensorInfromation licensorInfromation) throws IOException {
    in.beginObject();
    while (in.hasNext()) {
        String key = in.nextName();
        switch (key) {
        case Convention.OPEN_PLATFORM_AUTH_LICENSOR_BUSINESS_STORE_KEY:
            licensorInfromation.setBusinessStoreOpened(in.nextInt() == Convention.GLOBAL_TRUE_NUMBER);
            break;
        case Convention.OPEN_PLATFORM_AUTH_LICENSOR_BUSINESS_SCAN_KEY:
            licensorInfromation.setBusinessScanOpened(in.nextInt() == Convention.GLOBAL_TRUE_NUMBER);
            break;
        case Convention.OPEN_PLATFORM_AUTH_LICENSOR_BUSINESS_PAY_KEY:
            licensorInfromation.setBusinessPayOpened(in.nextInt() == Convention.GLOBAL_TRUE_NUMBER);
            break;
        case Convention.OPEN_PLATFORM_AUTH_LICENSOR_BUSINESS_CARD_KEY:
            licensorInfromation.setBusinessCardOpened(in.nextInt() == Convention.GLOBAL_TRUE_NUMBER);
            break;
        case Convention.OPEN_PLATFORM_AUTH_LICENSOR_BUSINESS_SHAKE_KEY:
            licensorInfromation.setBusinessShakeOpened(in.nextInt() == Convention.GLOBAL_TRUE_NUMBER);
            break;
        default:/*from w  ww .j  a v  a2 s. co  m*/
            if (in.hasNext()) {
                String value = in.nextString();
                logger.warn(LOG_UNKNOWN_JSON_KEY, key, value);
            }
        }
    }
    in.endObject();
}

From source file:io.grpc.internal.JsonParser.java

License:Apache License

private static Map<String, ?> parseJsonObject(JsonReader jr) throws IOException {
    jr.beginObject();
    Map<String, Object> obj = new LinkedHashMap<>();
    while (jr.hasNext()) {
        String name = jr.nextName();
        Object value = parseRecursive(jr);
        obj.put(name, value);//from w w  w . j  a v a  2s.  c o m
    }
    checkState(jr.peek() == JsonToken.END_OBJECT, "Bad token: " + jr.getPath());
    jr.endObject();
    return Collections.unmodifiableMap(obj);
}