modules/json/src/org/apache/axis2/json/gson/GsonXMLStreamWriter.java [136:288]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    private void writeStartJson(JsonObject jsonObject) throws IOException {

        if (jsonObject.getType() == JSONType.OBJECT) {
            jsonWriter.name(jsonObject.getName());
        } else if (jsonObject.getType() == JSONType.ARRAY) {
            jsonWriter.name(jsonObject.getName());
            jsonWriter.beginArray();

        } else if (jsonObject.getType() == JSONType.NESTED_ARRAY) {
            jsonWriter.name(jsonObject.getName());
            jsonWriter.beginArray();
            jsonWriter.beginObject();
            if (topNestedArrayObj == null) {
                topNestedArrayObj = jsonObject;
                processedJsonObjects.push(jsonObject);
            }
        } else if (jsonObject.getType() == JSONType.NESTED_OBJECT) {
            jsonWriter.name(jsonObject.getName());
            jsonWriter.beginObject();

        }

    }

    private void writeEndJson(JsonObject endJson) throws IOException {
        if (endJson.getType() == JSONType.OBJECT) {
            // nothing write to json writer
        } else if (endJson.getType() == JSONType.ARRAY) {
            jsonWriter.endArray();
        } else if (endJson.getType() == JSONType.NESTED_ARRAY) {
            jsonWriter.endArray();
        } else if (endJson.getType() == JSONType.NESTED_OBJECT) {
            jsonWriter.endObject();
        }

    }


    private JsonObject popStack() {
        if (topNestedArrayObj == null || stack.peek().getType() == JSONType.NESTED_OBJECT
                || stack.peek().getType() == JSONType.NESTED_ARRAY) {
            return stack.pop();
        } else {
            processedJsonObjects.push(stack.peek());
            return stack.pop();
        }
    }

    private void fillMiniStack(JsonObject nestedJsonObject) {

        while (!processedJsonObjects.peek().getName().equals(nestedJsonObject.getName())) {
            miniStack.push(processedJsonObjects.pop());
        }
        processedJsonObjects.pop();
    }


    /**
     * Writes a start tag to the output.  All writeStartElement methods
     * open a new scope in the internal namespace context.  Writing the
     * corresponding EndElement causes the scope to be closed.
     *
     * @param localName local name of the tag, may not be null
     * @throws javax.xml.stream.XMLStreamException
     *
     */

    public void writeStartElement(String localName) throws XMLStreamException {
        if (!isProcessed) {
            try {
                process();
            } catch (IOException e) {
                throw new XMLStreamException("Error occours while write first begin object ");
            }
        }
        JsonObject stackObj = null;
        try {
            if (miniStack.isEmpty()) {
                if (!queue.isEmpty()) {
                    JsonObject queObj = queue.peek();
                    if (queObj.getName().equals(localName)) {
                        if (flushObject != null) {
                            if (topNestedArrayObj != null && flushObject.getType() == JSONType.NESTED_ARRAY
                                    && flushObject.getName().equals(topNestedArrayObj.getName())) {
                                topNestedArrayObj = null;
                                processedJsonObjects.clear();
                            }
                            popStack();
                            writeEndJson(flushObject);
                            flushObject = null;
                        }

                        if (topNestedArrayObj != null && (queObj.getType() == JSONType.NESTED_ARRAY ||
                                queObj.getType() == JSONType.NESTED_OBJECT)) {
                            processedJsonObjects.push(queObj);
                        }
                        writeStartJson(queObj);
                        stack.push(queue.poll());
                    } else if (!stack.isEmpty()) {
                        stackObj = stack.peek();
                        if (stackObj.getName().equals(localName)) {
                            if (stackObj.getType() == JSONType.NESTED_ARRAY) {
                                fillMiniStack(stackObj);
                                jsonWriter.beginObject();
                                processedJsonObjects.push(stackObj);
                            }
                            flushObject = null;
                        } else {
                            throw new XMLStreamException("Invalid Staring element");
                        }
                    }
                } else {
                    if (!stack.isEmpty()) {
                        stackObj = stack.peek();
                        if (stackObj.getName().equals(localName)) {
                            flushObject = null;
                            if (stackObj.getType() == JSONType.NESTED_ARRAY) {
                                fillMiniStack(stackObj);
                                jsonWriter.beginObject();
                                processedJsonObjects.push(stackObj);
                            }
                        } else {
                            throw new XMLStreamException("Invalid Staring element");
                        }
                    } else {
                        throw new XMLStreamException("Invalid Starting  element");
                    }
                }
            } else {
                JsonObject queObj = miniStack.peek();
                if (queObj.getName().equals(localName)) {
                    if (flushObject != null) {
                        popStack();
                        writeEndJson(flushObject);
                        flushObject = null;
                    }
                    if (topNestedArrayObj != null && (queObj.getType() == JSONType.NESTED_OBJECT
                            || queObj.getType() == JSONType.NESTED_ARRAY)) {
                        processedJsonObjects.push(queObj);
                    }
                    writeStartJson(queObj);
                    stack.push(miniStack.pop());
                } else if (!stack.isEmpty()) {
                    stackObj = stack.peek();
                    if (stackObj.getName().equals(localName)) {
                        flushObject = null;
                        if (stackObj.getType() == JSONType.NESTED_ARRAY) {
                            fillMiniStack(stackObj);
                            jsonWriter.beginObject();
                            processedJsonObjects.push(stackObj);
                        }
                    } else {
                        throw new XMLStreamException("Invalid Staring element");
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



modules/json/src/org/apache/axis2/json/moshi/MoshiXMLStreamWriter.java [137:289]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    private void writeStartJson(JsonObject jsonObject) throws IOException {

        if (jsonObject.getType() == JSONType.OBJECT) {
            jsonWriter.name(jsonObject.getName());
        } else if (jsonObject.getType() == JSONType.ARRAY) {
            jsonWriter.name(jsonObject.getName());
            jsonWriter.beginArray();

        } else if (jsonObject.getType() == JSONType.NESTED_ARRAY) {
            jsonWriter.name(jsonObject.getName());
            jsonWriter.beginArray();
            jsonWriter.beginObject();
            if (topNestedArrayObj == null) {
                topNestedArrayObj = jsonObject;
                processedJsonObjects.push(jsonObject);
            }
        } else if (jsonObject.getType() == JSONType.NESTED_OBJECT) {
            jsonWriter.name(jsonObject.getName());
            jsonWriter.beginObject();

        }

    }

    private void writeEndJson(JsonObject endJson) throws IOException {
        if (endJson.getType() == JSONType.OBJECT) {
            // nothing write to json writer
        } else if (endJson.getType() == JSONType.ARRAY) {
            jsonWriter.endArray();
        } else if (endJson.getType() == JSONType.NESTED_ARRAY) {
            jsonWriter.endArray();
        } else if (endJson.getType() == JSONType.NESTED_OBJECT) {
            jsonWriter.endObject();
        }

    }


    private JsonObject popStack() {
        if (topNestedArrayObj == null || stack.peek().getType() == JSONType.NESTED_OBJECT
                || stack.peek().getType() == JSONType.NESTED_ARRAY) {
            return stack.pop();
        } else {
            processedJsonObjects.push(stack.peek());
            return stack.pop();
        }
    }

    private void fillMiniStack(JsonObject nestedJsonObject) {

        while (!processedJsonObjects.peek().getName().equals(nestedJsonObject.getName())) {
            miniStack.push(processedJsonObjects.pop());
        }
        processedJsonObjects.pop();
    }


    /**
     * Writes a start tag to the output.  All writeStartElement methods
     * open a new scope in the internal namespace context.  Writing the
     * corresponding EndElement causes the scope to be closed.
     *
     * @param localName local name of the tag, may not be null
     * @throws javax.xml.stream.XMLStreamException
     *
     */

    public void writeStartElement(String localName) throws XMLStreamException {
        if (!isProcessed) {
            try {
                process();
            } catch (IOException e) {
                throw new XMLStreamException("Error occours while write first begin object ");
            }
        }
        JsonObject stackObj = null;
        try {
            if (miniStack.isEmpty()) {
                if (!queue.isEmpty()) {
                    JsonObject queObj = queue.peek();
                    if (queObj.getName().equals(localName)) {
                        if (flushObject != null) {
                            if (topNestedArrayObj != null && flushObject.getType() == JSONType.NESTED_ARRAY
                                    && flushObject.getName().equals(topNestedArrayObj.getName())) {
                                topNestedArrayObj = null;
                                processedJsonObjects.clear();
                            }
                            popStack();
                            writeEndJson(flushObject);
                            flushObject = null;
                        }

                        if (topNestedArrayObj != null && (queObj.getType() == JSONType.NESTED_ARRAY ||
                                queObj.getType() == JSONType.NESTED_OBJECT)) {
                            processedJsonObjects.push(queObj);
                        }
                        writeStartJson(queObj);
                        stack.push(queue.poll());
                    } else if (!stack.isEmpty()) {
                        stackObj = stack.peek();
                        if (stackObj.getName().equals(localName)) {
                            if (stackObj.getType() == JSONType.NESTED_ARRAY) {
                                fillMiniStack(stackObj);
                                jsonWriter.beginObject();
                                processedJsonObjects.push(stackObj);
                            }
                            flushObject = null;
                        } else {
                            throw new XMLStreamException("Invalid Staring element");
                        }
                    }
                } else {
                    if (!stack.isEmpty()) {
                        stackObj = stack.peek();
                        if (stackObj.getName().equals(localName)) {
                            flushObject = null;
                            if (stackObj.getType() == JSONType.NESTED_ARRAY) {
                                fillMiniStack(stackObj);
                                jsonWriter.beginObject();
                                processedJsonObjects.push(stackObj);
                            }
                        } else {
                            throw new XMLStreamException("Invalid Staring element");
                        }
                    } else {
                        throw new XMLStreamException("Invalid Starting  element");
                    }
                }
            } else {
                JsonObject queObj = miniStack.peek();
                if (queObj.getName().equals(localName)) {
                    if (flushObject != null) {
                        popStack();
                        writeEndJson(flushObject);
                        flushObject = null;
                    }
                    if (topNestedArrayObj != null && (queObj.getType() == JSONType.NESTED_OBJECT
                            || queObj.getType() == JSONType.NESTED_ARRAY)) {
                        processedJsonObjects.push(queObj);
                    }
                    writeStartJson(queObj);
                    stack.push(miniStack.pop());
                } else if (!stack.isEmpty()) {
                    stackObj = stack.peek();
                    if (stackObj.getName().equals(localName)) {
                        flushObject = null;
                        if (stackObj.getType() == JSONType.NESTED_ARRAY) {
                            fillMiniStack(stackObj);
                            jsonWriter.beginObject();
                            processedJsonObjects.push(stackObj);
                        }
                    } else {
                        throw new XMLStreamException("Invalid Staring element");
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



