Example usage for com.badlogic.gdx.utils UBJsonWriter pop

List of usage examples for com.badlogic.gdx.utils UBJsonWriter pop

Introduction

In this page you can find the example usage for com.badlogic.gdx.utils UBJsonWriter pop.

Prototype

public UBJsonWriter pop() throws IOException 

Source Link

Document

Ends the current object or array and pops it off of the element stack.

Usage

From source file:br.com.questingsoftware.libgdx.g3db.G3DBConverter.java

License:Apache License

private void writeObject(JsonValue root, UBJsonWriter writer) throws IOException {
    if (root.type() == ValueType.array) {
        if (root.name() != null) {
            writer.array(root.name());//ww w.  j av a 2  s .c  o  m
        } else {
            writer.array();
        }
    } else {
        if (root.name() != null) {
            writer.object(root.name());
        } else {
            writer.object();
        }
    }

    JsonValue child = root.child();
    while (child != null) {
        switch (child.type()) {
        case booleanValue:
            if (child.name() != null) {
                writer.set(child.name(), child.asBoolean());
            } else {
                writer.value(child.asBoolean());
            }
            break;

        case doubleValue:
            if (child.name() != null) {
                writer.set(child.name(), child.asDouble());
            } else {
                writer.value(child.asDouble());
            }
            break;

        case longValue:
            if (child.name() != null) {
                writer.set(child.name(), child.asLong());
            } else {
                writer.value(child.asLong());
            }
            break;

        case stringValue:
            if (child.name() != null) {
                writer.set(child.name(), child.asString());
            } else {
                writer.value(child.asString());
            }
            break;

        case nullValue:
            if (child.name() != null) {
                writer.set(child.name());
            }
            break;

        case array:
        case object:
            writeObject(child, writer);
            break;
        }

        child = child.next();
    }

    writer.pop();
}