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.bimserver.client.ClientIfcModel.java

License:Open Source License

@SuppressWarnings({ "unused", "resource" })
public void getGeometry(IfcProduct ifcProduct) {
    try {/*from w  w w.  j a v a 2 s  .c o m*/
        Long downloadByOids = bimServerClient.getBimsie1ServiceInterface().downloadByOids(
                Collections.singleton(roid), Collections.singleton(ifcProduct.getOid()),
                getJsonGeometrySerializerOid(), true, false);
        InputStream downloadData = bimServerClient.getDownloadData(downloadByOids,
                getJsonGeometrySerializerOid());
        JsonReader jsonReader = new JsonReader(new InputStreamReader(downloadData));
        jsonReader.beginObject();
        if (jsonReader.nextName().equals("geometry")) {
            jsonReader.beginArray();
            while (jsonReader.hasNext()) {
                jsonReader.beginObject();
                if (jsonReader.nextName().equals("material")) {
                    String material = jsonReader.nextString();
                    if (jsonReader.nextName().equals("type")) {
                        String type = jsonReader.nextString();
                        if (jsonReader.nextName().equals("coreId")) {
                            String coreid = jsonReader.nextString();
                            if (jsonReader.nextName().equals("primitive")) {
                                String primitive = jsonReader.nextString();
                                if (jsonReader.nextName().equals("positions")) {
                                    jsonReader.beginArray();
                                    while (jsonReader.hasNext()) {
                                        double position = jsonReader.nextDouble();
                                    }
                                    jsonReader.endArray();
                                    if (jsonReader.nextName().equals("normals")) {
                                        jsonReader.beginArray();
                                        while (jsonReader.hasNext()) {
                                            double normal = jsonReader.nextDouble();
                                        }
                                        jsonReader.endArray();
                                        if (jsonReader.nextName().equals("nrindices")) {
                                            int nrindices = jsonReader.nextInt();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                jsonReader.endObject();
            }
            jsonReader.endArray();
        }
        jsonReader.endObject();
    } catch (Exception e) {
        LOGGER.error("", e);
    }
}

From source file:org.bimserver.deserializers.JsonDeserializer.java

License:Open Source License

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override//from   ww  w . ja v  a 2  s.c o m
public IfcModelInterface read(InputStream in, String filename, long fileSize) throws DeserializeException {
    IfcModelInterface model = new IfcModel();
    WaitingList<Long> waitingList = new WaitingList<Long>();
    JsonReader jsonReader = new JsonReader(new InputStreamReader(in));
    try {
        jsonReader.beginObject();
        if (jsonReader.nextName().equals("objects")) {
            jsonReader.beginArray();
            while (jsonReader.hasNext()) {
                jsonReader.beginObject();
                if (jsonReader.nextName().equals("__oid")) {
                    long oid = jsonReader.nextLong();
                    if (jsonReader.nextName().equals("__type")) {
                        String type = jsonReader.nextString();
                        EClass eClass = (EClass) Ifc2x3tc1Package.eINSTANCE.getEClassifier(type);
                        if (eClass == null) {
                            throw new DeserializeException("No class found with name " + type);
                        }
                        IdEObject object = (IdEObject) Ifc2x3tc1Factory.eINSTANCE.create(eClass);
                        // ((IdEObjectImpl) object).setDelegate(new
                        // ClientDelegate(this, object, null));
                        ((IdEObjectImpl) object).setOid(oid);
                        model.add(object.getOid(), object);
                        while (jsonReader.hasNext()) {
                            String featureName = jsonReader.nextName();
                            boolean embedded = false;
                            if (featureName.startsWith("__ref")) {
                                featureName = featureName.substring(5);
                            } else if (featureName.startsWith("__emb")) {
                                embedded = true;
                                featureName = featureName.substring(5);
                            }
                            EStructuralFeature eStructuralFeature = eClass.getEStructuralFeature(featureName);
                            if (eStructuralFeature == null) {
                                throw new DeserializeException(
                                        "Unknown field (" + featureName + ") on class " + eClass.getName());
                            }
                            if (eStructuralFeature.isMany()) {
                                jsonReader.beginArray();
                                if (eStructuralFeature instanceof EAttribute) {
                                    List list = (List) object.eGet(eStructuralFeature);
                                    List<String> stringList = null;

                                    if (eStructuralFeature.getEType() == EcorePackage.eINSTANCE
                                            .getEDoubleObject()
                                            || eStructuralFeature.getEType() == EcorePackage.eINSTANCE
                                                    .getEDouble()) {
                                        EStructuralFeature asStringFeature = eClass.getEStructuralFeature(
                                                eStructuralFeature.getName() + "AsString");
                                        stringList = (List<String>) object.eGet(asStringFeature);
                                    }

                                    while (jsonReader.hasNext()) {
                                        Object e = readPrimitive(jsonReader, eStructuralFeature);
                                        list.add(e);
                                        if (eStructuralFeature.getEType() == EcorePackage.eINSTANCE
                                                .getEDouble()) {
                                            double val = (Double) e;
                                            stringList.add("" + val); // TODO
                                            // this
                                            // is
                                            // losing
                                            // precision,
                                            // maybe
                                            // also
                                            // send
                                            // the
                                            // string
                                            // value?
                                        }
                                    }
                                } else if (eStructuralFeature instanceof EReference) {
                                    int index = 0;
                                    while (jsonReader.hasNext()) {
                                        if (embedded) {
                                            List list = (List) object.eGet(eStructuralFeature);
                                            jsonReader.beginObject();
                                            if (jsonReader.nextName().equals("__type")) {
                                                String t = jsonReader.nextString();
                                                IdEObject wrappedObject = (IdEObject) Ifc2x3tc1Factory.eINSTANCE
                                                        .create((EClass) Ifc2x3tc1Package.eINSTANCE
                                                                .getEClassifier(t));
                                                if (jsonReader.nextName().equals("value")) {
                                                    EStructuralFeature wv = wrappedObject.eClass()
                                                            .getEStructuralFeature("wrappedValue");
                                                    wrappedObject.eSet(wv, readPrimitive(jsonReader, wv));
                                                    list.add(wrappedObject);
                                                } else {
                                                    // error
                                                }
                                            }
                                            jsonReader.endObject();
                                        } else {
                                            long refOid = jsonReader.nextLong();
                                            waitingList.add(refOid,
                                                    new ListWaitingObject(object, eStructuralFeature, index));
                                            index++;
                                        }
                                    }
                                }
                                jsonReader.endArray();
                            } else {
                                if (eStructuralFeature instanceof EAttribute) {
                                    Object x = readPrimitive(jsonReader, eStructuralFeature);
                                    if (eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDouble()) {
                                        EStructuralFeature asStringFeature = object.eClass()
                                                .getEStructuralFeature(
                                                        eStructuralFeature.getName() + "AsString");
                                        object.eSet(asStringFeature, "" + x); // TODO
                                        // this
                                        // is
                                        // losing
                                        // precision,
                                        // maybe
                                        // also
                                        // send
                                        // the
                                        // string
                                        // value?
                                    }
                                    object.eSet(eStructuralFeature, x);
                                } else if (eStructuralFeature instanceof EReference) {
                                    if (eStructuralFeature.getName().equals("GlobalId")) {
                                        IfcGloballyUniqueId globallyUniqueId = Ifc2x3tc1Factory.eINSTANCE
                                                .createIfcGloballyUniqueId();
                                        globallyUniqueId.setWrappedValue(jsonReader.nextString());
                                        object.eSet(eStructuralFeature, globallyUniqueId);
                                    } else if (embedded) {
                                        jsonReader.beginObject();
                                        if (jsonReader.nextName().equals("__type")) {
                                            String t = jsonReader.nextString();
                                            IdEObject wrappedObject = (IdEObject) Ifc2x3tc1Factory.eINSTANCE
                                                    .create((EClass) Ifc2x3tc1Package.eINSTANCE
                                                            .getEClassifier(t));
                                            if (jsonReader.nextName().equals("value")) {
                                                EStructuralFeature wv = wrappedObject.eClass()
                                                        .getEStructuralFeature("wrappedValue");
                                                wrappedObject.eSet(wv, readPrimitive(jsonReader, wv));
                                                object.eSet(eStructuralFeature, wrappedObject);
                                            } else {
                                                // error
                                            }
                                        }
                                        jsonReader.endObject();
                                    } else {
                                        waitingList.add(jsonReader.nextLong(),
                                                new SingleWaitingObject(object, eStructuralFeature));
                                    }
                                }
                            }
                        }
                        if (waitingList.containsKey(oid)) {
                            waitingList.updateNode(oid, eClass, object);
                        }
                    }
                }
                jsonReader.endObject();
            }
            jsonReader.endArray();
        }
        jsonReader.endObject();
    } catch (IOException e1) {
        e1.printStackTrace();
    } catch (IfcModelInterfaceException e1) {
        e1.printStackTrace();
    } finally {
        try {
            jsonReader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return model;
}

From source file:org.bimserver.emf.SharedJsonDeserializer.java

License:Open Source License

@SuppressWarnings("rawtypes")
public IfcModelInterface read(InputStream in, IfcModelInterface model, boolean checkWaitingList)
        throws DeserializeException {
    if (model.getPackageMetaData().getSchemaDefinition() == null) {
        throw new DeserializeException("No SchemaDefinition available");
    }/*w w  w  .j a  va  2 s .com*/
    WaitingList<Long> waitingList = new WaitingList<Long>();
    final boolean log = false;
    if (log) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try {
            IOUtils.copy(in, baos);
            File file = new File("debug.json");
            System.out.println(file.getAbsolutePath());
            FileUtils.writeByteArrayToFile(file, baos.toByteArray());
        } catch (IOException e) {
            e.printStackTrace();
        }
        in = new ByteArrayInputStream(baos.toByteArray());
    }
    JsonReader jsonReader = new JsonReader(new InputStreamReader(in, Charsets.UTF_8));
    int nrObjects = 0;
    try {
        JsonToken peek = jsonReader.peek();
        if (peek != null && peek == JsonToken.BEGIN_OBJECT) {
            jsonReader.beginObject();
            peek = jsonReader.peek();
            while (peek == JsonToken.NAME) {
                String nextName = jsonReader.nextName();
                if (nextName.equals("objects")) {
                    jsonReader.beginArray();
                    while (jsonReader.hasNext()) {
                        nrObjects++;
                        processObject(model, waitingList, jsonReader, null);
                    }
                    jsonReader.endArray();
                } else if (nextName.equals("header")) {
                    IfcHeader ifcHeader = (IfcHeader) processObject(model, waitingList, jsonReader,
                            StorePackage.eINSTANCE.getIfcHeader());
                    model.getModelMetaData().setIfcHeader(ifcHeader);
                }
                peek = jsonReader.peek();
            }
            jsonReader.endObject();
        }
    } catch (IOException e) {
        LOGGER.error("", e);
    } catch (IfcModelInterfaceException e) {
        LOGGER.error("", e);
    } finally {
        LOGGER.info("# Objects: " + nrObjects);
        try {
            jsonReader.close();
        } catch (IOException e) {
            LOGGER.error("", e);
        }
    }
    boolean checkUnique = false;
    if (checkUnique) {
        for (IdEObject idEObject : model.getValues()) {
            for (EStructuralFeature eStructuralFeature : idEObject.eClass().getEAllStructuralFeatures()) {
                Object value = idEObject.eGet(eStructuralFeature);
                if (eStructuralFeature instanceof EReference) {
                    if (eStructuralFeature.isMany()) {
                        List list = (List) value;
                        if (eStructuralFeature.isUnique()) {
                            Set<Object> t = new HashSet<>();
                            for (Object v : list) {
                                if (t.contains(v)) {
                                    //                           LOGGER.error("NOT UNIQUE " + idEObject.eClass().getName() + "." + eStructuralFeature.getName());
                                }
                                t.add(v);
                            }
                        }
                    }
                }
            }
        }
    }
    if (checkWaitingList && waitingList.size() > 0) {
        try {
            waitingList.dumpIfNotEmpty();
        } catch (BimServerClientException e) {
            e.printStackTrace();
        }
        throw new DeserializeException("Waitinglist should be empty (" + waitingList.size() + ")");
    }
    return model;
}

From source file:org.bimserver.emf.SharedJsonDeserializer.java

License:Open Source License

@SuppressWarnings({ "rawtypes", "unchecked" })
private IdEObject processObject(IfcModelInterface model, WaitingList<Long> waitingList, JsonReader jsonReader,
        EClass eClass) throws IOException, DeserializeException, IfcModelInterfaceException {
    IdEObjectImpl object = null;/*from ww w.j av a  2 s .  com*/
    jsonReader.beginObject();
    if (jsonReader.nextName().equals("_i")) {
        long oid = jsonReader.nextLong();
        if (jsonReader.nextName().equals("_t")) {
            String type = jsonReader.nextString();
            if (eClass == null) {
                eClass = model.getPackageMetaData().getEClassIncludingDependencies(type);
            }
            if (eClass == null) {
                throw new DeserializeException("No class found with name " + type);
            }
            if (model.containsNoFetch(oid)) {
                object = (IdEObjectImpl) model.getNoFetch(oid);
            } else {
                if (eClass == StorePackage.eINSTANCE.getIfcHeader()) {
                    object = (IdEObjectImpl) StoreFactory.eINSTANCE.createIfcHeader();
                } else {
                    object = (IdEObjectImpl) model.create(eClass, oid);
                }
            }

            if (jsonReader.nextName().equals("_s")) {
                int state = jsonReader.nextInt();
                if (state == 1) {
                    object.setLoadingState(State.LOADED);
                    while (jsonReader.hasNext()) {
                        String featureName = jsonReader.nextName();
                        boolean embedded = false;
                        if (featureName.startsWith("_r")) {
                            featureName = featureName.substring(2);
                        } else if (featureName.startsWith("_e")) {
                            embedded = true;
                            featureName = featureName.substring(2);
                        }
                        EStructuralFeature eStructuralFeature = eClass.getEStructuralFeature(featureName);
                        if (eStructuralFeature == null) {
                            throw new DeserializeException(
                                    "Unknown field (" + featureName + ") on class " + eClass.getName());
                        }
                        if (eStructuralFeature.isMany()) {
                            jsonReader.beginArray();
                            if (eStructuralFeature instanceof EAttribute) {
                                List list = (List) object.eGet(eStructuralFeature);
                                List<String> stringList = null;

                                if (eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDoubleObject()
                                        || eStructuralFeature.getEType() == EcorePackage.eINSTANCE
                                                .getEDouble()) {
                                    EStructuralFeature asStringFeature = eClass
                                            .getEStructuralFeature(eStructuralFeature.getName() + "AsString");
                                    stringList = (List<String>) object.eGet(asStringFeature);
                                }

                                while (jsonReader.hasNext()) {
                                    Object e = readPrimitive(jsonReader, eStructuralFeature);
                                    list.add(e);
                                    if (eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDouble()) {
                                        double val = (Double) e;
                                        stringList.add("" + val); // TODO
                                        // this
                                        // is
                                        // losing
                                        // precision,
                                        // maybe
                                        // also
                                        // send
                                        // the
                                        // string
                                        // value?
                                    }
                                }
                            } else if (eStructuralFeature instanceof EReference) {
                                int index = 0;
                                AbstractEList list = (AbstractEList) object.eGet(eStructuralFeature);
                                while (jsonReader.hasNext()) {
                                    if (embedded) {
                                        JsonToken peek = jsonReader.peek();
                                        if (peek == JsonToken.NUMBER) {
                                            long refOid = jsonReader.nextLong();
                                            processRef(model, waitingList, object, eStructuralFeature, index,
                                                    list, refOid);
                                        } else {
                                            jsonReader.beginObject();
                                            String nextName = jsonReader.nextName();
                                            if (nextName.equals("_t")) {
                                                String t = jsonReader.nextString();
                                                IdEObject wrappedObject = (IdEObject) model
                                                        .create(model.getPackageMetaData().getEClass(t), -1);
                                                if (jsonReader.nextName().equals("_v")) {
                                                    EStructuralFeature wv = wrappedObject.eClass()
                                                            .getEStructuralFeature("wrappedValue");
                                                    wrappedObject.eSet(wv, readPrimitive(jsonReader, wv));
                                                    list.add(wrappedObject);
                                                } else {
                                                    // error
                                                }
                                            } else if (nextName.equals("_i")) {
                                                // Not all are embedded...
                                                long refOid = jsonReader.nextLong();
                                                processRef(model, waitingList, object, eStructuralFeature,
                                                        index, list, refOid);
                                            }
                                            jsonReader.endObject();
                                        }
                                    } else {
                                        long refOid = jsonReader.nextLong();
                                        processRef(model, waitingList, object, eStructuralFeature, index, list,
                                                refOid);
                                    }
                                    index++;
                                }
                            }
                            jsonReader.endArray();
                        } else {
                            if (eStructuralFeature instanceof EAttribute) {
                                Object x = readPrimitive(jsonReader, eStructuralFeature);
                                if (eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDouble()) {
                                    EStructuralFeature asStringFeature = object.eClass()
                                            .getEStructuralFeature(eStructuralFeature.getName() + "AsString");
                                    if (asStringFeature != null) {
                                        object.eSet(asStringFeature, "" + x); // TODO
                                    }
                                    // this
                                    // is
                                    // losing
                                    // precision,
                                    // maybe
                                    // also
                                    // send
                                    // the
                                    // string
                                    // value?
                                }
                                object.eSet(eStructuralFeature, x);
                            } else if (eStructuralFeature instanceof EReference) {
                                if (eStructuralFeature.getName().equals("GlobalId")) {
                                    IfcGloballyUniqueId globallyUniqueId = Ifc2x3tc1Factory.eINSTANCE
                                            .createIfcGloballyUniqueId();
                                    globallyUniqueId.setWrappedValue(jsonReader.nextString());
                                    object.eSet(eStructuralFeature, globallyUniqueId);
                                } else if (embedded) {
                                    jsonReader.beginObject();
                                    if (jsonReader.nextName().equals("_t")) {
                                        String t = jsonReader.nextString();
                                        IdEObject wrappedObject = (IdEObject) model.create(
                                                model.getPackageMetaData().getEClassIncludingDependencies(t),
                                                -1);
                                        if (eStructuralFeature.getEAnnotation("dbembed") != null) {
                                            for (EStructuralFeature eStructuralFeature2 : wrappedObject.eClass()
                                                    .getEAllStructuralFeatures()) {
                                                String fn = jsonReader.nextName();
                                                if (fn.equals(eStructuralFeature2.getName())) {
                                                    wrappedObject.eSet(eStructuralFeature2,
                                                            readPrimitive(jsonReader, eStructuralFeature2));
                                                } else {
                                                    throw new DeserializeException(
                                                            fn + " / " + eStructuralFeature2.getName());
                                                }
                                            }
                                            object.eSet(eStructuralFeature, wrappedObject);
                                        } else {
                                            if (jsonReader.nextName().equals("_v")) {
                                                EStructuralFeature wv = wrappedObject.eClass()
                                                        .getEStructuralFeature("wrappedValue");
                                                wrappedObject.eSet(wv, readPrimitive(jsonReader, wv));
                                                object.eSet(eStructuralFeature, wrappedObject);
                                            }
                                        }
                                    }
                                    jsonReader.endObject();
                                } else {
                                    long refOid = jsonReader.nextLong();
                                    boolean isInverse = false;
                                    EntityDefinition entityBN = model.getPackageMetaData().getSchemaDefinition()
                                            .getEntityBN(object.eClass().getName());
                                    if (entityBN != null) {
                                        // Some entities like GeometryInfo/Data are not in IFC schema, but valid
                                        Attribute attributeBN = entityBN
                                                .getAttributeBNWithSuper(eStructuralFeature.getName());
                                        if (attributeBN != null) {
                                            if (attributeBN instanceof InverseAttribute) {
                                                isInverse = true;
                                            }
                                        }
                                    }
                                    if (!isInverse) {
                                        if (model.contains(refOid)) {
                                            object.eSet(eStructuralFeature, model.get(refOid));
                                        } else {
                                            waitingList.add(refOid, new SingleWaitingObject(-1, object,
                                                    (EReference) eStructuralFeature));
                                        }
                                    }
                                }
                            }
                        }
                    }
                } else {
                    // state not_loaded
                }
                if (waitingList.containsKey(oid)) {
                    waitingList.updateNode(oid, eClass, object);
                }
                model.add(object.getOid(), object);
            } else {
                LOGGER.info("_s expected");
            }
        } else {
            LOGGER.info("_t expected");
        }
    } else {
        LOGGER.info("_i expected");
    }
    jsonReader.endObject();
    return object;
}

From source file:org.cgiar.ccafs.marlo.utils.StringTypeAdapter.java

License:Open Source License

@Override
public String read(JsonReader jsonReader) throws IOException {
    if (jsonReader.peek() == JsonToken.NULL) {
        jsonReader.nextNull();//  w w  w . j a  va  2s . c  o m
        return null;
    }

    try {
        String value = jsonReader.nextString();

        return value;

    } catch (IllegalStateException e) {

        String values = "";

        jsonReader.beginArray();
        while (jsonReader.hasNext()) {
            if (values.length() < 1) {
                values = jsonReader.nextString();
            } else {
                values = values + "," + jsonReader.nextString();
            }
        }
        jsonReader.endArray();
        return values;
    }
}

From source file:org.cyanogenmod.changelog.ChangelogParser.java

License:Open Source License

/**
 * Read a Collection of ChangeInfo JSON entities
 * See http://review.cyanogenmod.org/Documentation/rest-api.html
 * @param reader the JsonReader to use/*from   w ww  . ja  v a  2  s.  c  o  m*/
 * @return a List of Changes
 * @throws IOException
 */
private List<Change> parseChangeInfoList(JsonReader reader) throws IOException {
    List<Change> changes = new LinkedList<>();
    reader.beginArray();
    while (reader.hasNext()) {
        Change newChange = parseChangeInfo(reader);
        // check if its a legit change
        if (newChange.isDeviceSpecific())
            changes.add(newChange);
    }
    reader.endArray();
    return changes;
}

From source file:org.cyanogenmod.changelog.ChangelogParser.java

License:Open Source License

/**
 * Read ChangeInfo JSON entity//from  w  w  w .  ja  v a  2s. c om
 * See http://review.cyanogenmod.org/Documentation/rest-api.html
 * @param reader the JsonReader to use
 * @return the parsed Change.
 * @throws IOException
 */
private Change parseChangeInfo(JsonReader reader) throws IOException {
    Change change = new Change();
    reader.beginObject();
    while (reader.hasNext()) {
        switch (reader.nextName()) {
        case "_number":
            change.setChangeId(reader.nextString());
            break;
        case "project":
            change.setProject(reader.nextString());
            break;
        case "subject":
            change.setSubject(reader.nextString());
            break;
        case "updated":
            change.setLastUpdate(parseTimestamp(reader.nextString()));
            break;
        case "insertions":
            change.setInsertions(reader.nextInt());
            break;
        case "deletions":
            change.setDeletions(reader.nextInt());
            break;
        default:
            reader.skipValue();
        }
    }
    reader.endObject();
    return change;
}

From source file:org.dice_research.topicmodeling.io.json.AbstractDocumentJsonReader.java

License:Open Source License

public Document readDocument(JsonReader reader) {
    try {/*from   w  ww.  j av  a2 s . co m*/
        // Check that an object begins
        if ((!reader.hasNext()) && (!JsonToken.BEGIN_OBJECT.equals(reader.peek()))) {
            return null;
        }
    } catch (IOException e) {
        LOGGER.warn("Got an IOException when trying to check whether a JSON object begins. Moving on.", e);
    }
    try {
        return gson.fromJson(reader, Document.class);
    } catch (Exception e) {
        LOGGER.error("Couldn't read document from JSON. Returning null.", e);
        return null;
    }
}

From source file:org.eclipse.lsp4j.adapters.HoverTypeAdapter.java

License:Open Source License

public Hover read(final JsonReader in) throws IOException {
    JsonToken nextToken = in.peek();/*from  w w  w  .j  a  v a 2s . c om*/
    if (nextToken == JsonToken.NULL) {
        return null;
    }

    Hover result = new Hover();
    in.beginObject();
    while (in.hasNext()) {
        String name = in.nextName();
        switch (name) {
        case "contents":
            result.setContents(readContents(in));
            break;
        case "range":
            result.setRange(readRange(in));
            break;
        default:
            in.skipValue();
        }
    }
    in.endObject();
    return result;
}

From source file:org.eclipse.lsp4j.adapters.InitializeParamsTypeAdapter.java

License:Open Source License

public InitializeParams read(final JsonReader in) throws IOException {
    JsonToken nextToken = in.peek();//from w ww  .j  av  a 2  s .  co m
    if (nextToken == JsonToken.NULL) {
        return null;
    }

    InitializeParams result = new InitializeParams();
    in.beginObject();
    while (in.hasNext()) {
        String name = in.nextName();
        switch (name) {
        case "processId":
            result.setProcessId(readProcessId(in));
            break;
        case "rootPath":
            result.setRootPath(readRootPath(in));
            break;
        case "rootUri":
            result.setRootUri(readRootUri(in));
            break;
        case "initializationOptions":
            result.setInitializationOptions(readInitializationOptions(in));
            break;
        case "capabilities":
            result.setCapabilities(readCapabilities(in));
            break;
        case "clientName":
            result.setClientName(readClientName(in));
            break;
        case "trace":
            result.setTrace(readTrace(in));
            break;
        case "workspaceFolders":
            result.setWorkspaceFolders(readWorkspaceFolders(in));
            break;
        default:
            in.skipValue();
        }
    }
    in.endObject();
    return result;
}