Package javax.json

Examples of javax.json.JsonArray


        return result.getString(JSON_OBJECT_MESSAGE);
    }

    public Set<String> getChildren(String path) {
        JsonObject result = managementResource.path(path).request(MediaType.APPLICATION_JSON).get(JsonObject.class);
        JsonArray childrenEntries = result.getJsonArray(JSON_ARRAY_CHILDREN);
        if (childrenEntries == null) {
            return null;
        }
        Set<String> children = new HashSet<>();
        for (JsonValue value : childrenEntries) {
View Full Code Here


            }
            out.println(w);
            out.println("<br>...done<br>");
           
            out.println("<br>Creating a simple array ...<br>");
            JsonArray jsonArray = Json.createArrayBuilder()
                    .add(Json.createObjectBuilder().add("apple","red"))
                    .add(Json.createObjectBuilder().add("banana","yellow"))
                    .build();
            w = new StringWriter();
            try (JsonWriter writer = Json.createWriter(w)) {
View Full Code Here

            SAXUnmarshallerHandler rootContentHandler = null;
            if (getContentHandler() instanceof SAXUnmarshallerHandler) {
                rootContentHandler = (SAXUnmarshallerHandler) getContentHandler();
            }
            JsonArray jsonArray = (JsonArray) jsonValue;
            int size = jsonArray.size();

            List list = new ArrayList(size);
            for (int x = 0; x < size; x++) {
                parseRoot(jsonArray.get(x));
                if (getContentHandler() instanceof SAXUnmarshallerHandler) {
                    SAXUnmarshallerHandler saxUnmarshallerHandler = (SAXUnmarshallerHandler) contentHandler;
                    list.add(saxUnmarshallerHandler.getObject());
                    saxUnmarshallerHandler.setObject(null);
                } else if (getContentHandler() instanceof UnmarshalRecord) {
View Full Code Here

            while (iter.hasNext()) {
                Entry<String, JsonValue> nextEntry = iter.next();
                parsePair(nextEntry.getKey(), nextEntry.getValue());
            }
        } else if(valueType == ValueType.ARRAY) {
            JsonArray childArray = (JsonArray)jsonValue;
            int size = childArray.size();
              
            List list = new ArrayList(size);           
            for(int x=0; x<size; x++) {
                JsonValue nextArrayValue = childArray.get(x);
                parseValue(nextArrayValue);
            }
        }
  }
View Full Code Here

            return;
        }
        ValueType valueType = jsonValue.getValueType();

        if (valueType == ValueType.ARRAY) {
            JsonArray jsonArray = (JsonArray) jsonValue;
            String parentLocalName = name;

            if (attributePrefix != null && parentLocalName.startsWith(attributePrefix)) {
                // do nothing;
                return;
            }
            String uri = Constants.EMPTY_STRING;
            if (namespaceAware && namespaces != null) {
                if (parentLocalName.length() > 2) {
                    int nsIndex = parentLocalName.indexOf(namespaceSeparator, 1);
                    if (nsIndex > -1) {
                        String prefix = parentLocalName.substring(0, nsIndex);
                        uri = namespaces.resolveNamespacePrefix(prefix);
                    }
                    if (uri == null) {
                        uri = namespaces.getDefaultNamespaceURI();
                    } else {
                        parentLocalName = parentLocalName.substring(nsIndex + 1);
                    }
                } else {
                    uri = namespaces.getDefaultNamespaceURI();
                }
            }

            boolean isTextValue = isTextValue(parentLocalName);
            int arraySize = jsonArray.size();
            if (arraySize == 0) {
                if (contentHandler instanceof UnmarshalRecord) {
                    UnmarshalRecord ur = (UnmarshalRecord) contentHandler;
                    XPathNode node = ur.getNonAttributeXPathNode(uri, parentLocalName, parentLocalName, null);
                    if (node != null) {
                        NodeValue nv = node.getNodeValue();
                        if (nv == null && node.getTextNode() != null) {
                            nv = node.getTextNode().getUnmarshalNodeValue();
                        }
                        if (nv != null && nv.isContainerValue()) {
                            ur.getContainerInstance(((ContainerValue) nv));
                        }
                    }
                }
            }
            startCollection();

            XPathFragment groupingXPathFragment = null;
            XPathFragment itemXPathFragment = null;
            if (contentHandler instanceof UnmarshalRecord) {
                UnmarshalRecord unmarshalRecord = (UnmarshalRecord) contentHandler;
                if (unmarshalRecord.getUnmarshaller().isWrapperAsCollectionName()) {
                    XPathNode unmarshalRecordXPathNode = unmarshalRecord.getXPathNode();
                    if (null != unmarshalRecordXPathNode) {
                        XPathFragment currentFragment = new XPathFragment();
                        currentFragment.setLocalName(parentLocalName);
                        currentFragment.setNamespaceURI(uri);
                        currentFragment.setNamespaceAware(namespaceAware);
                        XPathNode groupingXPathNode = unmarshalRecordXPathNode.getNonAttributeChildrenMap().get(currentFragment);
                        if (groupingXPathNode != null) {
                            if (groupingXPathNode.getUnmarshalNodeValue() instanceof CollectionGroupingElementNodeValue) {
                                groupingXPathFragment = groupingXPathNode.getXPathFragment();
                                contentHandler.startElement(uri, parentLocalName, parentLocalName, new AttributesImpl());
                                XPathNode itemXPathNode = groupingXPathNode.getNonAttributeChildren().get(0);
                                itemXPathFragment = itemXPathNode.getXPathFragment();
                            } else if (groupingXPathNode.getUnmarshalNodeValue() == null) {
                                XPathNode itemXPathNode = groupingXPathNode.getNonAttributeChildren().get(0);
                                if (itemXPathNode != null) {
                                    if (((MappingNodeValue) itemXPathNode.getUnmarshalNodeValue()).isContainerValue()) {
                                        groupingXPathFragment = groupingXPathNode.getXPathFragment();
                                        contentHandler.startElement(uri, parentLocalName, parentLocalName, new AttributesImpl());
                                        itemXPathFragment = itemXPathNode.getXPathFragment();
                                    }
                                }
                            }
                        }
                    }
                }

                for (int i = 0; i < arraySize; i++) {
                    JsonValue nextArrayValue = jsonArray.get(i);
                    if (nextArrayValue.getValueType() == ValueType.NULL) {
                        ((UnmarshalRecord) contentHandler).setNil(true);
                    }

                    if (!isTextValue) {
View Full Code Here

                get(JsonObject.class);
        assertThat(out.getBoolean("vatIdAvailable"), is(in.isVatIdAvailable()));
        assertThat(out.getInt("numberOfDays"), is(in.getNumberOfDays()));
        assertThat(out.getInt("numberOfAttendees"), is(in.getNumberOfAttendees()));
        //all
        JsonArray result = this.rut.request().
                accept(MediaType.APPLICATION_JSON).
                get(JsonArray.class);
        assertNotNull(result);
        assertTrue(result.size() > 0);

    }
View Full Code Here

    }

    @Test
    public void convertEmptyListToJson() {
        mockQuery(Registration.findAll, Collections.EMPTY_LIST);
        final JsonArray result = this.cut.allAsJson();
        assertNotNull(result);
        assertTrue(result.isEmpty());
    }
View Full Code Here

        List<Registration> registrations = new ArrayList<>();
        Registration expected = mock(Registration.class);
        when(expected.getId()).thenReturn(42l);
        registrations.add(expected);
        mockQuery(Registration.findAll, registrations);
        final JsonArray result = this.cut.allAsJson();
        assertNotNull(result);
        assertThat(result.size(), is(1));
        JsonObject actual = result.getJsonObject(0);
        JsonNumber actualId = actual.getJsonNumber(Registrations.CONFIRMATION_ID);
        assertThat(expected.getId(), is(actualId.longValue()));

    }
View Full Code Here

        return registrations.find(registrationId);
    }

    @GET
    public Response all() {
        JsonArray registrationList = this.registrations.allAsJson();
        if (registrationList == null || registrationList.isEmpty()) {
            return Response.noContent().build();
        }
        return Response.ok(registrationList).build();
    }
View Full Code Here

                                uri = namespaces.getDefaultNamespaceURI();
                            }
                        }

                        if (nextValue.getValueType() == ValueType.ARRAY) {
                            JsonArray jsonArray = (JsonArray) nextValue;
                            if (jsonArray.size() == 0) {
                                attributesList.add(new Attribute(uri, attributeLocalName, attributeLocalName, ""));
                            }
                            for (int y = 0; y < jsonArray.size(); y++) {
                                JsonValue nextChildValue = jsonArray.get(y);
                                addSimpleAttribute(attributesList, uri, attributeLocalName, nextChildValue);
                            }
                        } else {
                            addSimpleAttribute(attributesList, uri, attributeLocalName, nextValue);
                        }
View Full Code Here

TOP

Related Classes of javax.json.JsonArray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.