Java 类javax.json.stream.JsonGenerationException 实例源码

项目:yasson    文件:Marshaller.java   
/**
 * Marshals given object to provided Writer or OutputStream.
 *
 * @param object object to marshall
 * @param jsonGenerator generator to use
 */
public void marshall(Object object, JsonGenerator jsonGenerator) {
    try {
        final ContainerModel model = new ContainerModel(runtimeType != null ? runtimeType : object.getClass(), null);
        serializeRoot(object, jsonGenerator, model);
    } catch (JsonbException e) {
        logger.severe(e.getMessage());
        throw e;
    } finally {
        try {
            jsonGenerator.close();
        } catch (JsonGenerationException jge) {
            logger.severe(jge.getMessage());
        }
    }
}
项目:cookjson    文件:BsonGenerator.java   
private JsonGenerator writeValue (String value)
{
    byte[] bytes = value.getBytes (BOM.utf8);
    Utils.setInt (m_bytes, bytes.length + 1);
    writeElement (BsonType.String, m_name, 4);
    try
    {
        w (bytes);
        w (0);
    }
    catch (IOException ex)
    {
        throw new JsonGenerationException (ex.getMessage (), ex);
    }
    return this;
}
项目:cookjson    文件:BsonGenerator.java   
@Override
    public JsonGenerator writeEnd ()
    {
        boolean isArray = popState ();
        if (isArray)
        {
            m_index = m_arrayCounts.remove (m_arrayCounts.size () - 1);
        }
//      assert Debug.debug ("WRITE: " + (isArray ? "END_ARRAY" : "END_OBJECT"));
        try
        {
            w (0);
            m_name = null;
        }
        catch (IOException ex)
        {
            throw new JsonGenerationException (ex.getMessage (), ex);
        }
        return this;
    }
项目:cookjson    文件:BsonGenerator.java   
@Override
    public JsonGenerator write (JsonValue value)
    {
//      assert Debug.debug ("WRITE: JsonValue");
        if (m_state != GeneratorState.IN_ARRAY)
        {
            if (m_state == GeneratorState.INITIAL)
            {
                if (!(value instanceof JsonArray) &&
                    !(value instanceof JsonObject))
                    throw new JsonGenerationException (ErrorMessage.invalidContext);
            }
            else
                throw new JsonGenerationException (ErrorMessage.notInArrayContext);
        }
        return writeValue (value);
    }
项目:cookjson    文件:BsonGenerator.java   
@Override
public void flush ()
{
    try
    {
        if (m_pos > 0)
        {
            m_os.write (m_buffer, 0, m_pos);
            m_pos = 0;
        }
        m_os.flush ();
    }
    catch (IOException ex)
    {
        throw new JsonGenerationException (ex.getMessage (), ex);
    }
}
项目:cookjson    文件:TextJsonGenerator.java   
@Override
    public JsonGenerator writeStartObject ()
    {
//      assert Debug.debug ("WRITE: START_OBJECT");
        if (m_state != GeneratorState.INITIAL &&
            m_state != GeneratorState.IN_ARRAY)
            throw new JsonGenerationException (ErrorMessage.invalidContext);
        try
        {
            writeComma ();
            w ('{');
            pushState (false);
            m_first = true;
            return this;
        }
        catch (IOException ex)
        {
            throw new JsonGenerationException (ex.getMessage (), ex);
        }
    }
项目:cookjson    文件:TextJsonGenerator.java   
@Override
    public JsonGenerator writeStartObject (String name)
    {
//      assert Debug.debug ("WRITE: KEY_NAME: " + name);
//      assert Debug.debug ("WRITE: START_OBJECT");
        if (m_state != GeneratorState.IN_OBJECT)
            throw new JsonGenerationException (ErrorMessage.notInObjectContext);
        try
        {
            writeName (name);
            w ('{');
            pushState (false);
            m_first = true;
            return this;
        }
        catch (IOException ex)
        {
            throw new JsonGenerationException (ex.getMessage (), ex);
        }
    }
项目:cookjson    文件:TextJsonGenerator.java   
@Override
    public JsonGenerator writeStartArray ()
    {
//      assert Debug.debug ("WRITE: START_ARRAY");
        if (m_state != GeneratorState.INITIAL &&
            m_state != GeneratorState.IN_ARRAY)
            throw new JsonGenerationException (ErrorMessage.invalidContext);
        try
        {
            writeComma ();
            w ('[');
            pushState (true);
            m_first = true;
            return this;
        }
        catch (IOException ex)
        {
            throw new JsonGenerationException (ex.getMessage (), ex);
        }
    }
项目:cookjson    文件:TextJsonGenerator.java   
@Override
    public JsonGenerator writeStartArray (String name)
    {
//      assert Debug.debug ("WRITE: KEY_NAME: " + name);
//      assert Debug.debug ("WRITE: START_ARRAY");
        if (m_state != GeneratorState.IN_OBJECT)
            throw new JsonGenerationException (ErrorMessage.notInObjectContext);
        try
        {
            writeName (name);
            w ('[');
            pushState (true);
            m_first = true;
            return this;
        }
        catch (IOException ex)
        {
            throw new JsonGenerationException (ex.getMessage (), ex);
        }
    }
项目:cookjson    文件:TextJsonGenerator.java   
@Override
    public JsonGenerator write (String name, JsonValue value)
    {
//      assert Debug.debug ("WRITE: KEY_NAME: " + name);
//      assert Debug.debug ("WRITE: JsonValue");
        if (m_state != GeneratorState.IN_OBJECT)
            throw new JsonGenerationException (ErrorMessage.notInObjectContext);
        try
        {
            writeName (name);
            writeValue (value);
            return this;
        }
        catch (IOException ex)
        {
            throw new JsonGenerationException (ex.getMessage (), ex);
        }
    }
项目:cookjson    文件:TextJsonGenerator.java   
@Override
    public JsonGenerator write (String name, byte[] value)
    {
//      assert Debug.debug ("WRITE: KEY_NAME: " + name);
//      assert Debug.debug ("WRITE: VALUE_STRING");
        if (m_state != GeneratorState.IN_OBJECT)
            throw new JsonGenerationException (ErrorMessage.notInObjectContext);
        try
        {
            writeName (name);
            if (m_binaryFormat == BinaryFormat.BINARY_FORMAT_BASE64)
                base64Encode (value);
            else
                hexEncode (value);
            return this;
        }
        catch (IOException ex)
        {
            throw new JsonGenerationException (ex.getMessage (), ex);
        }
    }
项目:cookjson    文件:TextJsonGenerator.java   
@Override
    public JsonGenerator write (String name, String value)
    {
//      assert Debug.debug ("WRITE: KEY_NAME: " + name);
//      assert Debug.debug ("WRITE: VALUE_STRING");
        if (m_state != GeneratorState.IN_OBJECT)
            throw new JsonGenerationException (ErrorMessage.notInObjectContext);
        try
        {
            writeName (name);
            quote (value);
            return this;
        }
        catch (IOException ex)
        {
            throw new JsonGenerationException (ex.getMessage (), ex);
        }
    }
项目:cookjson    文件:TextJsonGenerator.java   
@Override
    public JsonGenerator write (String name, BigInteger value)
    {
//      assert Debug.debug ("WRITE: KEY_NAME: " + name);
//      assert Debug.debug ("WRITE: VALUE_NUMBER: (BigInteger)" + value);
        if (m_state != GeneratorState.IN_OBJECT)
            throw new JsonGenerationException (ErrorMessage.notInObjectContext);
        try
        {
            writeName (name);
            w (value.toString ());
            return this;
        }
        catch (IOException ex)
        {
            throw new JsonGenerationException (ex.getMessage (), ex);
        }
    }
项目:cookjson    文件:TextJsonGenerator.java   
@Override
    public JsonGenerator write (String name, BigDecimal value)
    {
//      assert Debug.debug ("WRITE: KEY_NAME: " + name);
//      assert Debug.debug ("WRITE: VALUE_NUMBER: (BigDecimal)" + value);
        if (m_state != GeneratorState.IN_OBJECT)
            throw new JsonGenerationException (ErrorMessage.notInObjectContext);
        try
        {
            writeName (name);
            w (value.toString ());
            return this;
        }
        catch (IOException ex)
        {
            throw new JsonGenerationException (ex.getMessage (), ex);
        }
    }
项目:cookjson    文件:TextJsonGenerator.java   
@Override
    public JsonGenerator write (String name, int value)
    {
//      assert Debug.debug ("WRITE: KEY_NAME: " + name);
//      assert Debug.debug ("WRITE: VALUE_NUMBER: (int)" + value);
        if (m_state != GeneratorState.IN_OBJECT)
            throw new JsonGenerationException (ErrorMessage.notInObjectContext);
        try
        {
            writeName (name);
            wi (value);
            return this;
        }
        catch (IOException ex)
        {
            throw new JsonGenerationException (ex.getMessage (), ex);
        }
    }
项目:cookjson    文件:TextJsonGenerator.java   
@Override
    public JsonGenerator write (String name, long value)
    {
//      assert Debug.debug ("WRITE: KEY_NAME: " + name);
//      assert Debug.debug ("WRITE: VALUE_NUMBER: (long)" + value);
        if (m_state != GeneratorState.IN_OBJECT)
            throw new JsonGenerationException (ErrorMessage.notInObjectContext);
        try
        {
            writeName (name);
            w (Long.toString (value));
            return this;
        }
        catch (IOException ex)
        {
            throw new JsonGenerationException (ex.getMessage (), ex);
        }
    }
项目:cookjson    文件:TextJsonGenerator.java   
@Override
    public JsonGenerator write (String name, double value)
    {
//      assert Debug.debug ("WRITE: KEY_NAME: " + name);
//      assert Debug.debug ("WRITE: VALUE_NUMBER: (double)" + value);
        if (m_state != GeneratorState.IN_OBJECT)
            throw new JsonGenerationException (ErrorMessage.notInObjectContext);
        try
        {
            writeName (name);
            w (DoubleUtils.toString (value));
            return this;
        }
        catch (IOException ex)
        {
            throw new JsonGenerationException (ex.getMessage (), ex);
        }
    }
项目:cookjson    文件:TextJsonGenerator.java   
@Override
    public JsonGenerator write (String name, boolean value)
    {
//      assert Debug.debug ("WRITE: KEY_NAME: " + name);
//      assert Debug.debug ("WRITE: VALUE_" + (value ? "TRUE" : "FALSE"));
        if (m_state != GeneratorState.IN_OBJECT)
            throw new JsonGenerationException (ErrorMessage.notInObjectContext);
        try
        {
            writeName (name);
            w (value ? "true" : "false");
            return this;
        }
        catch (IOException ex)
        {
            throw new JsonGenerationException (ex.getMessage (), ex);
        }
    }
项目:cookjson    文件:TextJsonGenerator.java   
@Override
    public JsonGenerator writeNull (String name)
    {
//      assert Debug.debug ("WRITE: KEY_NAME: " + name);
//      assert Debug.debug ("WRITE: VALUE_NULL");
        if (m_state != GeneratorState.IN_OBJECT)
            throw new JsonGenerationException (ErrorMessage.notInObjectContext);
        try
        {
            writeName (name);
            w ("null");
            return this;
        }
        catch (IOException ex)
        {
            throw new JsonGenerationException (ex.getMessage (), ex);
        }
    }
项目:cookjson    文件:TextJsonGenerator.java   
@Override
    public JsonGenerator writeEnd ()
    {
        if (m_state == GeneratorState.END)
            throw new JsonGenerationException (ErrorMessage.invalidContext);
        boolean isArray = popState ();
//      assert Debug.debug ("WRITE: " + (isArray ? "END_ARRAY" : "END_OBJECT"));
        m_first = false;
        char ch = isArray ? ']' : '}';
        try
        {
            w (ch);
        }
        catch (IOException ex)
        {
            throw new JsonGenerationException (ex.getMessage (), ex);
        }
        return this;
    }
项目:cookjson    文件:TextJsonGenerator.java   
@Override
    public JsonGenerator write (JsonValue value)
    {
//      assert Debug.debug ("WRITE: JsonValue");
        if (m_state != GeneratorState.IN_ARRAY)
        {
            if (m_state == GeneratorState.INITIAL)
            {
                if (!(value instanceof JsonArray) &&
                    !(value instanceof JsonObject))
                    throw new JsonGenerationException (ErrorMessage.invalidContext);
            }
            else
                throw new JsonGenerationException (ErrorMessage.notInArrayContext);
        }
        try
        {
            writeComma ();
            return writeValue (value);
        }
        catch (IOException ex)
        {
            throw new JsonGenerationException (ex.getMessage (), ex);
        }
    }
项目:cookjson    文件:TextJsonGenerator.java   
@Override
    public JsonGenerator write (byte[] value)
    {
//      assert Debug.debug ("WRITE: VALUE_STRING");
        if (m_state != GeneratorState.IN_ARRAY)
            throw new JsonGenerationException (ErrorMessage.notInObjectContext);
        try
        {
            writeComma ();
            if (m_binaryFormat == BinaryFormat.BINARY_FORMAT_BASE64)
                base64Encode (value);
            else
                hexEncode (value);
            return this;
        }
        catch (IOException ex)
        {
            throw new JsonGenerationException (ex.getMessage (), ex);
        }
    }
项目:cookjson    文件:TextJsonGenerator.java   
@Override
    public JsonGenerator write (String value)
    {
//      assert Debug.debug ("WRITE: VALUE_STRING");
        if (m_state != GeneratorState.IN_ARRAY)
            throw new JsonGenerationException (ErrorMessage.notInArrayContext);
        try
        {
            writeComma ();
            quote (value);
        }
        catch (IOException ex)
        {
            throw new JsonGenerationException (ex.getMessage (), ex);
        }
        return this;
    }
项目:cookjson    文件:TextJsonGenerator.java   
@Override
    public JsonGenerator write (BigDecimal value)
    {
//      assert Debug.debug ("WRITE: VALUE_NUMBER: (BigDecimal)" + value);
        if (m_state != GeneratorState.IN_ARRAY)
            throw new JsonGenerationException (ErrorMessage.notInArrayContext);
        try
        {
            writeComma ();
            w (value.toString ());
        }
        catch (IOException ex)
        {
            throw new JsonGenerationException (ex.getMessage (), ex);
        }
        return this;
    }
项目:cookjson    文件:TextJsonGenerator.java   
@Override
    public JsonGenerator write (BigInteger value)
    {
//      assert Debug.debug ("WRITE: VALUE_NUMBER: (BigInteger)" + value);
        if (m_state != GeneratorState.IN_ARRAY)
            throw new JsonGenerationException (ErrorMessage.notInArrayContext);
        try
        {
            writeComma ();
            w (value.toString ());
        }
        catch (IOException ex)
        {
            throw new JsonGenerationException (ex.getMessage (), ex);
        }
        return this;
    }
项目:cookjson    文件:TextJsonGenerator.java   
@Override
    public JsonGenerator write (int value)
    {
//      assert Debug.debug ("WRITE: VALUE_NUMBER: (int)" + value);
        if (m_state != GeneratorState.IN_ARRAY)
            throw new JsonGenerationException (ErrorMessage.notInArrayContext);
        try
        {
            writeComma ();
            wi (value);
        }
        catch (IOException ex)
        {
            throw new JsonGenerationException (ex.getMessage (), ex);
        }
        return this;
    }
项目:cookjson    文件:TextJsonGenerator.java   
@Override
    public JsonGenerator write (long value)
    {
//      assert Debug.debug ("WRITE: VALUE_NUMBER: (long)" + value);
        if (m_state != GeneratorState.IN_ARRAY)
            throw new JsonGenerationException (ErrorMessage.notInArrayContext);
        try
        {
            writeComma ();
            w (Long.toString (value));
        }
        catch (IOException ex)
        {
            throw new JsonGenerationException (ex.getMessage (), ex);
        }
        return this;
    }
项目:cookjson    文件:TextJsonGenerator.java   
@Override
    public JsonGenerator write (double value)
    {
//      assert Debug.debug ("WRITE: VALUE_NUMBER: (double)" + value);
        if (m_state != GeneratorState.IN_ARRAY)
            throw new JsonGenerationException (ErrorMessage.notInArrayContext);
        try
        {
            writeComma ();
            w (DoubleUtils.toString (value));
        }
        catch (IOException ex)
        {
            throw new JsonGenerationException (ex.getMessage (), ex);
        }
        return this;
    }
项目:cookjson    文件:TextJsonGenerator.java   
@Override
    public JsonGenerator write (boolean value)
    {
//      assert Debug.debug ("WRITE: VALUE_" + (value ? "TRUE" : "FALSE"));
        if (m_state != GeneratorState.IN_ARRAY)
            throw new JsonGenerationException (ErrorMessage.notInArrayContext);
        try
        {
            writeComma ();
            w (value ? "true" : "false");
        }
        catch (IOException ex)
        {
            throw new JsonGenerationException (ex.getMessage (), ex);
        }
        return this;
    }
项目:cookjson    文件:TextJsonGenerator.java   
@Override
    public JsonGenerator writeNull ()
    {
//      assert Debug.debug ("WRITE: VALUE_NULL");
        if (m_state != GeneratorState.IN_ARRAY)
            throw new JsonGenerationException (ErrorMessage.notInArrayContext);
        try
        {
            writeComma ();
            w ("null");
        }
        catch (IOException ex)
        {
            throw new JsonGenerationException (ex.getMessage (), ex);
        }
        return this;
    }
项目:cookjson    文件:TextJsonGenerator.java   
@Override
public void flush ()
{
    try
    {
        if (m_pos > 0)
        {
            m_out.write (m_buffer, 0, m_pos);
            m_pos = 0;
        }
        m_out.flush ();
    }
    catch (IOException ex)
    {
        throw new JsonGenerationException (ex.getMessage (), ex);
    }
}
项目:johnzon    文件:JsonGeneratorImpl.java   
@Override
public JsonGenerator writeKey(final String key) {
    final GeneratorState currentState = currentState();
    if (!currentState.acceptsKey) {
        throw new JsonGenerationException("state " + currentState + " does not accept a key");
    }
    if (currentState == GeneratorState.IN_OBJECT) {
        justWrite(COMMA_CHAR);
        writeEol();
    }

    writeIndent();

    writeCachedKey(key);
    state.push(GeneratorState.AFTER_KEY);
    return this;
}
项目:johnzon    文件:JsonGeneratorImpl.java   
@Override
public void close() {
    try {
        if (currentState() != GeneratorState.END) {
            throw new JsonGenerationException("Invalid json");
        }
    } finally {
        flushBuffer();
        try {
            writer.close();
        } catch (final IOException e) {
            throw new JsonException(e.getMessage(), e);
        } finally {
            bufferProvider.release(buffer);
        }
    }
}
项目:cookjson    文件:BsonGenerator.java   
private JsonGenerator writeElement (int type, String name, int length)
{
    try
    {
        w (type);
        writeCString (name);
        w (m_bytes, 0, length);
    }
    catch (IOException ex)
    {
        throw new JsonGenerationException (ex.getMessage (), ex);
    }
    return this;
}
项目:cookjson    文件:BsonGenerator.java   
private JsonGenerator writeRootObject ()
{
    try
    {
        w (m_bytes, 0, 4);
    }
    catch (IOException ex)
    {
        throw new JsonGenerationException (ex.getMessage (), ex);
    }
    return this;
}
项目:cookjson    文件:BsonGenerator.java   
private JsonGenerator writeValue (byte[] value)
{
    try
    {
        Utils.setInt (m_bytes, value.length);
        writeElement (BsonType.Binary, m_name, 4);
        w (0);
        w (value);
    }
    catch (IOException ex)
    {
        throw new JsonGenerationException (ex.getMessage (), ex);
    }
    return this;
}
项目:cookjson    文件:BsonGenerator.java   
private JsonGenerator writeNullValue ()
{
    try
    {
        w (BsonType.Null);
        writeCString (m_name);
    }
    catch (IOException ex)
    {
        throw new JsonGenerationException (ex.getMessage (), ex);
    }
    return this;
}
项目:cookjson    文件:BsonGenerator.java   
@Override
    public JsonGenerator writeStartObject ()
    {
//      assert Debug.debug ("WRITE: START_OBJECT");
        if (m_state != GeneratorState.INITIAL &&
            m_state != GeneratorState.IN_ARRAY)
            throw new JsonGenerationException (ErrorMessage.invalidContext);
        return writeObject (m_state == GeneratorState.INITIAL);
    }
项目:cookjson    文件:BsonGenerator.java   
@Override
    public JsonGenerator writeStartObject (String name)
    {
//      assert Debug.debug ("WRITE: KEY_NAME: " + name);
//      assert Debug.debug ("WRITE: START_OBJECT");
        if (m_state != GeneratorState.IN_OBJECT)
            throw new JsonGenerationException (ErrorMessage.notInObjectContext);
        checkName (name);
        return writeObject (false);
    }
项目:cookjson    文件:BsonGenerator.java   
@Override
    public JsonGenerator writeStartArray ()
    {
//      assert Debug.debug ("WRITE: START_ARRAY");
        if (m_state != GeneratorState.INITIAL &&
            m_state != GeneratorState.IN_ARRAY)
            throw new JsonGenerationException (ErrorMessage.invalidContext);
        return writeArray (m_state == GeneratorState.INITIAL);
    }