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

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

Introduction

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

Prototype

public boolean hasNext() throws IOException 

Source Link

Document

Returns true if the current array or object has another element.

Usage

From source file:org.komodo.rest.relational.json.StatusObjectSerializer.java

License:Open Source License

/**
 * {@inheritDoc}/* w  w  w.  j a  v  a  2 s . co m*/
 *
 * @see com.google.gson.TypeAdapter#read(com.google.gson.stream.JsonReader)
 */
@Override
public KomodoStatusObject read(final JsonReader in) throws IOException {
    final KomodoStatusObject status = new KomodoStatusObject();
    in.beginObject();

    while (in.hasNext()) {
        final String name = in.nextName();

        switch (name) {
        case KomodoStatusObject.TITLE_LABEL:
            status.setTitle(in.nextString());
            break;
        case KomodoStatusObject.INFO_LABEL:
            Map<String, String> attributes = BUILDER.fromJson(in, Map.class);
            status.setAttributes(attributes);
            break;
        default:
            throw new IOException(Messages.getString(UNEXPECTED_JSON_TOKEN, name));
        }
    }

    in.endObject();

    return status;
}

From source file:org.komodo.rest.relational.json.StorageAttributesSerializer.java

License:Open Source License

/**
 * {@inheritDoc}/*  ww w. j  a v a  2s  . c  o  m*/
 *
 * @see com.google.gson.TypeAdapter#read(com.google.gson.stream.JsonReader)
 */
@Override
public KomodoStorageAttributes read(final JsonReader in) throws IOException {
    final KomodoStorageAttributes storageAttr = new KomodoStorageAttributes();
    in.beginObject();

    while (in.hasNext()) {
        final String name = in.nextName();

        if (readContent(in, storageAttr, name) != null)
            continue;

        switch (name) {
        case KomodoStorageAttributes.STORAGE_TYPE_LABEL:
            storageAttr.setStorageType(in.nextString());
            break;
        case KomodoStorageAttributes.ARTIFACT_PATH_LABEL:
            storageAttr.setArtifactPath(in.nextString());
            break;
        case KomodoStorageAttributes.PARAMETERS_LABEL:
            Map<String, String> parameters = BUILDER.fromJson(in, Map.class);
            for (Map.Entry<String, String> parameter : parameters.entrySet()) {
                storageAttr.setParameter(parameter.getKey(), parameter.getValue());
            }
            break;
        case KomodoStorageAttributes.DOCUMENT_TYPE_LABEL:
            String docTypeValue = in.nextString();
            DocumentType docType = DocumentType.documentType(docTypeValue);
            storageAttr.setDocumentType(docType);
            break;
        default:
            throw new IOException(Messages.getString(UNEXPECTED_JSON_TOKEN, name));
        }
    }

    in.endObject();

    return storageAttr;
}

From source file:org.komodo.rest.relational.json.StorageTypeDescriptorSerializer.java

License:Open Source License

@Override
public RestStorageTypeDescriptor read(JsonReader in) throws IOException {
    final RestStorageTypeDescriptor storageTypeDescriptor = new RestStorageTypeDescriptor();
    in.beginObject();/*  w  w w. j a v  a 2  s .com*/

    while (in.hasNext()) {
        final String name = in.nextName();

        switch (name) {
        case RestStorageTypeDescriptor.NAME_LABEL:
            storageTypeDescriptor.setName(in.nextString());
            break;
        case RestStorageTypeDescriptor.DESCRIPTION_LABEL:
            storageTypeDescriptor.setDescription(in.nextString());
            break;
        case RestStorageTypeDescriptor.REQUIRED_LABEL:
            storageTypeDescriptor.setRequired(in.nextBoolean());
            break;
        case RestStorageTypeDescriptor.ENCODED_LABEL:
            storageTypeDescriptor.setEncoded(in.nextBoolean());
            break;
        default:
            throw new IOException(Messages.getString(UNEXPECTED_JSON_TOKEN, name));
        }
    }

    in.endObject();

    return storageTypeDescriptor;
}

From source file:org.komodo.rest.relational.json.StorageTypeSerializer.java

License:Open Source License

/**
 * {@inheritDoc}//from w w  w  .  j a va  2s  .co m
 *
 * @see com.google.gson.TypeAdapter#read(com.google.gson.stream.JsonReader)
 */
@Override
public RestStorageType read(final JsonReader in) throws IOException {
    final RestStorageType storageType = new RestStorageType();
    in.beginObject();

    while (in.hasNext()) {
        final String name = in.nextName();

        switch (name) {
        case RestStorageType.NAME_LABEL:
            storageType.setName(in.nextString());
            break;
        case RestStorageType.DESCRIPTION_LABEL:
            storageType.setDescription(in.nextString());
            break;
        case RestStorageType.DESCRIPTORS_LABEL:
            RestStorageTypeDescriptor[] descriptors = BUILDER.fromJson(in, RestStorageTypeDescriptor[].class);
            storageType.setDescriptors(descriptors);
            break;
        default:
            throw new IOException(Messages.getString(UNEXPECTED_JSON_TOKEN, name));
        }
    }

    in.endObject();

    return storageType;
}

From source file:org.komodo.rest.relational.json.TeiidAttributesSerializer.java

License:Open Source License

/**
 * {@inheritDoc}//from www  .  ja  v a  2s.  c o  m
 *
 * @see com.google.gson.TypeAdapter#read(com.google.gson.stream.JsonReader)
 */
@Override
public KomodoTeiidAttributes read(final JsonReader in) throws IOException {
    final KomodoTeiidAttributes teiidAttrs = new KomodoTeiidAttributes();
    in.beginObject();

    while (in.hasNext()) {
        final String name = in.nextName();

        switch (name) {
        case KomodoTeiidAttributes.ADMIN_USER_LABEL:
            teiidAttrs.setAdminUser(in.nextString());
            break;
        case KomodoTeiidAttributes.ADMIN_PASSWD_LABEL:
            teiidAttrs.setAdminPasswd(in.nextString());
            break;
        case KomodoTeiidAttributes.ADMIN_PORT_LABEL:
            teiidAttrs.setAdminPort(in.nextInt());
            break;
        case KomodoTeiidAttributes.ADMIN_SECURE_LABEL:
            teiidAttrs.setAdminSecure(in.nextBoolean());
            break;
        case KomodoTeiidAttributes.JDBC_USER_LABEL:
            teiidAttrs.setJdbcUser(in.nextString());
            break;
        case KomodoTeiidAttributes.JDBC_PASSWD_LABEL:
            teiidAttrs.setJdbcPasswd(in.nextString());
            break;
        case KomodoTeiidAttributes.JDBC_PORT_LABEL:
            teiidAttrs.setJdbcPort(in.nextInt());
            break;
        case KomodoTeiidAttributes.JDBC_SECURE_LABEL:
            teiidAttrs.setJdbcSecure(in.nextBoolean());
            break;
        default:
            throw new IOException(Messages.getString(UNEXPECTED_JSON_TOKEN, name));
        }
    }

    in.endObject();

    return teiidAttrs;
}

From source file:org.komodo.rest.relational.json.TeiidVdbStatusSerializer.java

License:Open Source License

/**
 * {@inheritDoc}// w  ww.ja v a2s .c  om
 *
 * @see org.komodo.rest.relational.json.AbstractEntitySerializer#read(com.google.gson.stream.JsonReader)
 */
@Override
public RestTeiidVdbStatus read(final JsonReader in) throws IOException {
    final RestTeiidVdbStatus entity = createEntity();

    beginRead(in);

    while (in.hasNext()) {
        final String name = in.nextName();

        if (RestTeiidVdbStatus.VDBS_LABEL.equals(name)) {
            final RestTeiidVdbStatusVdb[] vdbStatuses = BUILDER.fromJson(in, RestTeiidVdbStatusVdb[].class);
            entity.setVdbProperties(Arrays.asList(vdbStatuses));
        } else if (LINKS.equals(name))
            readLinks(in, entity);
        else {
            JsonToken token = in.peek();
            switch (token) {
            case BOOLEAN:
                entity.addTuple(name, in.nextBoolean());
                break;
            case NUMBER:
                entity.addTuple(name, in.nextInt());
                break;
            case STRING:
                entity.addTuple(name, in.nextString());
                break;
            case NULL:
                in.nextNull();
                entity.addTuple(name, null);
                break;
            case BEGIN_ARRAY:
                final String[] value = BUILDER.fromJson(in, String[].class);
                entity.addTuple(name, value);
                break;
            default:
                throw new IOException(Messages.getString(Messages.Error.UNEXPECTED_JSON_TOKEN, name));
            }
        }
    }

    if (!isComplete(entity)) {
        throw new IOException(Messages.getString(INCOMPLETE_JSON, getClass().getSimpleName()));
    }

    endRead(in);
    return entity;
}

From source file:org.komodo.rest.relational.json.TeiidVdbStatusVdbSerializer.java

License:Open Source License

/**
 * {@inheritDoc}//from w  ww.java 2s . c  o  m
 *
 * @see com.google.gson.TypeAdapter#read(com.google.gson.stream.JsonReader)
 */
@Override
public RestTeiidVdbStatusVdb read(final JsonReader in) throws IOException {
    final RestTeiidVdbStatusVdb vdb = new RestTeiidVdbStatusVdb();
    in.beginObject();

    while (in.hasNext()) {
        final String name = in.nextName();

        switch (name) {
        case RestTeiidVdbStatusVdb.TEIID_VDB_STATUS_NAME:
            vdb.setName(in.nextString());
            break;
        case RestTeiidVdbStatusVdb.TEIID_VDB_STATUS_DEPLOYED_NAME:
            vdb.setDeployedName(in.nextString());
            break;
        case RestTeiidVdbStatusVdb.TEIID_VDB_STATUS_VERSION:
            vdb.setVersion(in.nextString());
            break;
        case RestTeiidVdbStatusVdb.TEIID_VDB_STATUS_ACTIVE:
            vdb.setActive(in.nextBoolean());
            break;
        case RestTeiidVdbStatusVdb.TEIID_VDB_STATUS_LOADING:
            vdb.setLoading(in.nextBoolean());
            break;
        case RestTeiidVdbStatusVdb.TEIID_VDB_STATUS_FAILED:
            vdb.setFailed(in.nextBoolean());
            break;
        case RestTeiidVdbStatusVdb.TEIID_VDB_STATUS_ERROR:
            final String[] errors = BUILDER.fromJson(in, String[].class);
            vdb.setErrors(Arrays.asList(errors));
            break;
        default:
            throw new IOException(Messages.getString(UNEXPECTED_JSON_TOKEN, name));
        }
    }

    in.endObject();

    return vdb;
}

From source file:org.komodo.rest.relational.json.VdbUpdateAttributesSerializer.java

License:Open Source License

/**
 * {@inheritDoc}/*w ww .  jav  a 2  s . c  o m*/
 *
 * @see com.google.gson.TypeAdapter#read(com.google.gson.stream.JsonReader)
 */
@Override
public KomodoVdbUpdateAttributes read(final JsonReader in) throws IOException {
    final KomodoVdbUpdateAttributes updateAttrs = new KomodoVdbUpdateAttributes();
    in.beginObject();

    while (in.hasNext()) {
        final String name = in.nextName();

        switch (name) {
        case KomodoVdbUpdateAttributes.VDB_NAME_LABEL:
            updateAttrs.setVdbName(in.nextString());
            break;
        case KomodoVdbUpdateAttributes.MODEL_NAME_LABEL:
            updateAttrs.setModelName(in.nextString());
            break;
        case KomodoVdbUpdateAttributes.TEIID_VDB_NAME_LABEL:
            updateAttrs.setTeiidVdbName(in.nextString());
            break;
        case KomodoVdbUpdateAttributes.TEIID_MODEL_NAME_LABEL:
            updateAttrs.setTeiidModelName(in.nextString());
            break;
        default:
            throw new IOException(Messages.getString(UNEXPECTED_JSON_TOKEN, name));
        }
    }

    in.endObject();

    return updateAttrs;
}

From source file:org.lanternpowered.server.data.persistence.json.JsonDataFormat.java

License:MIT License

private static void readView(JsonReader reader, DataView view) throws IOException {
    reader.beginObject();//from   w  w  w.j a  va 2s  .  com
    while (reader.hasNext()) {
        DataQuery key = DataQuery.of(reader.nextName());

        if (reader.peek() == JsonToken.BEGIN_OBJECT) {
            // Check this early so we don't need to copy the view
            readView(reader, view.createView(key));
        } else {
            view.set(key, read0(reader));
        }
    }
    reader.endObject();
}

From source file:org.lanternpowered.server.data.persistence.json.JsonDataFormat.java

License:MIT License

private static List<?> readArray(JsonReader reader) throws IOException {
    reader.beginArray();//from  ww  w  .  j  a  v a2s. c om
    final List<Object> result = new ArrayList<>();
    while (reader.hasNext()) {
        result.add(read0(reader));
    }
    reader.endArray();
    return result;
}