javax.json.stream

Interface JsonGenerator

    • Field Detail

      • PRETTY_PRINTING

        static final String PRETTY_PRINTING
        Configuration property to generate JSON prettily. All providers must support this property. The value of the property could be be anything.
        See Also:
        Constant Field Values
    • Method Detail

      • writeStartObject

        JsonGenerator writeStartObject()
        Writes the JSON start object character. It starts a new child object context within which JSON name/value pairs can be written to the object. This method is valid only in an array context or in no context (when a context is not yet started). This method can only be called once in no context.
        Returns:
        this generator
        Throws:
        JsonException - if an i/o error occurs (IOException would be cause of JsonException)
        JsonGenerationException - if this method is called within an object context or if it is called more than once in no context.
      • writeStartObject

        JsonGenerator writeStartObject(String name)
        Writes the JSON name/start object character pair in the current object context. It starts a new child object context within which JSON name/value pairs can be written to the object.
        Parameters:
        name - a name within the JSON name/object pair to be written
        Returns:
        this generator
        Throws:
        JsonException - if an i/o error occurs (IOException would be cause of JsonException)
        JsonGenerationException - if this method is not called within an object context
      • writeStartArray

        JsonGenerator writeStartArray()
        Writes the JSON start array character. It starts a new child array context within which JSON values can be written to the array. This method is valid only in an array context or in no context (when a context is not yet started). This method can only be called once in no context.
        Returns:
        this generator
        Throws:
        JsonException - if an i/o error occurs (IOException would be cause of JsonException)
        JsonGenerationException - if this method is called within an object context or if called more than once in no context
      • writeStartArray

        JsonGenerator writeStartArray(String name)
        Writes the JSON name/start array character pair with in the current object context. It starts a new child array context within which JSON values can be written to the array.
        Parameters:
        name - a name within the JSON name/array pair to be written
        Returns:
        this generator
        Throws:
        JsonException - if an i/o error occurs (IOException would be cause of JsonException)
        JsonGenerationException - if this method is not called within an object context
      • write

        JsonGenerator write(String name,
                            JsonValue value)
        Writes a JSON name/value pair in the current object context.
        Parameters:
        name - a name in the JSON name/value pair to be written in current JSON object
        value - a value in the JSON name/value pair to be written in current JSON object
        Returns:
        this generator
        Throws:
        JsonException - if an i/o error occurs (IOException would be cause of JsonException)
        JsonGenerationException - if this method is not called within an object context
      • write

        JsonGenerator write(String name,
                            String value)
        Writes a JSON name/string value pair in the current object context. The specified value is written as JSON string value.
        Parameters:
        name - a name in the JSON name/string pair to be written in current JSON object
        value - a value in the JSON name/string pair to be written in current JSON object
        Returns:
        this generator
        Throws:
        JsonException - if an i/o error occurs (IOException would be cause of JsonException)
        JsonGenerationException - if this method is not called within an object context
      • write

        JsonGenerator write(String name,
                            BigInteger value)
        Writes a JSON name/number value pair in the current object context. The specified value is written as a JSON number value. The string new BigDecimal(value).toString() is used as the text value for writing.
        Parameters:
        name - a name in the JSON name/number pair to be written in current JSON object
        value - a value in the JSON name/number pair to be written in current JSON object
        Returns:
        this generator
        Throws:
        JsonException - if an i/o error occurs (IOException would be cause of JsonException)
        JsonGenerationException - if this method is not called within an object context.
      • write

        JsonGenerator write(String name,
                            BigDecimal value)
        Writes a JSON name/number value pair in the current object context. The specified value is written as a JSON number value. The specified value's toString() is used as the text value for writing.
        Parameters:
        name - a name in the JSON name/number pair to be written in current JSON object
        value - a value in the JSON name/number pair to be written in current JSON object
        Returns:
        this generator
        Throws:
        JsonException - if an i/o error occurs (IOException would be cause of JsonException)
        JsonGenerationException - if this method is not called within an object context.
      • write

        JsonGenerator write(String name,
                            int value)
        Writes a JSON name/number value pair in the current object context. The specified value is written as a JSON number value. The string new BigDecimal(value).toString() is used as the text value for writing.
        Parameters:
        name - a name in the JSON name/number pair to be written in current JSON object
        value - a value in the JSON name/number pair to be written in current JSON object
        Returns:
        this generator
        Throws:
        JsonException - if an i/o error occurs (IOException would be cause of JsonException)
        JsonGenerationException - if this method is not called within an object context.
      • write

        JsonGenerator write(String name,
                            long value)
        Writes a JSON name/number value pair in the current object context. The specified value is written as a JSON number value. The string new BigDecimal(value).toString() is used as the text value for writing.
        Parameters:
        name - a name in the JSON name/number pair to be written in current JSON object
        value - a value in the JSON name/number pair to be written in current JSON object
        Returns:
        this generator
        Throws:
        JsonException - if an i/o error occurs (IOException would be cause of JsonException)
        JsonGenerationException - if this method is not called within an object context.
      • write

        JsonGenerator write(String name,
                            double value)
        Writes a JSON name/number value pair in the current object context. The specified value is written as a JSON number value. The string BigDecimal.valueOf(double).toString() is used as the text value for writing.
        Parameters:
        name - a name in the JSON name/number pair to be written in current JSON object
        value - a value in the JSON name/number pair to be written in current JSON object
        Returns:
        this generator
        Throws:
        JsonException - if an i/o error occurs (IOException would be cause of JsonException)
        NumberFormatException - if the value is Not-a-Number(NaN) or infinity.
        JsonGenerationException - if this method is not called within an object context
      • write

        JsonGenerator write(String name,
                            boolean value)
        Writes a JSON name/boolean value pair in the current object context. If value is true, it writes the JSON true value, otherwise it writes the JSON false value.
        Parameters:
        name - a name in the JSON name/boolean pair to be written in current JSON object
        value - a value in the JSON name/boolean pair to be written in current JSON object
        Returns:
        this generator
        Throws:
        JsonException - if an i/o error occurs (IOException would be cause of JsonException)
        JsonGenerationException - if this method is not called within an object context.
      • writeNull

        JsonGenerator writeNull(String name)
        Writes a JSON name/null value pair in an current object context.
        Parameters:
        name - a name in the JSON name/null pair to be written in current JSON object
        Returns:
        this generator
        Throws:
        JsonException - if an i/o error occurs (IOException would be cause of JsonException)
        JsonGenerationException - if this method is not called within an object context
      • writeEnd

        JsonGenerator writeEnd()
        Writes the end of the current context. If the current context is an array context, this method writes the end-of-array character (']'). If the current context is an object context, this method writes the end-of-object character ('}'). After writing the end of the current context, the parent context becomes the new current context.
        Returns:
        this generator
        Throws:
        JsonException - if an i/o error occurs (IOException would be cause of JsonException)
        JsonGenerationException - if this method is called in no context.
      • write

        JsonGenerator write(JsonValue value)
        Writes the specified value as a JSON value within the current array context.
        Parameters:
        value - a value to be written in current JSON array
        Returns:
        this generator
        Throws:
        JsonException - if an i/o error occurs (IOException would be cause of JsonException)
        JsonGenerationException - if this method is not called within an array context.
      • write

        JsonGenerator write(String value)
        Writes the specified value as a JSON string value within the current array context.
        Parameters:
        value - a value to be written in current JSON array
        Returns:
        this generator
        Throws:
        JsonException - if an i/o error occurs (IOException would be cause of JsonException)
        JsonGenerationException - if this method is not called within an array context
      • write

        JsonGenerator write(BigDecimal value)
        Writes the specified value as a JSON number value within the current array context. The specified value's toString() is used as the the text value for writing.
        Parameters:
        value - a value to be written in current JSON array
        Returns:
        this generator
        Throws:
        JsonException - if an i/o error occurs (IOException would be cause of JsonException)
        JsonGenerationException - if this method is not called within an array context
        See Also:
        JsonNumber
      • write

        JsonGenerator write(BigInteger value)
        Writes the specified value as a JSON number value within the current array context. The string new BigDecimal(value).toString() is used as the text value for writing.
        Parameters:
        value - a value to be written in current JSON array
        Returns:
        this generator.
        Throws:
        JsonException - if an i/o error occurs (IOException would be cause of JsonException)
        JsonGenerationException - if this method is not called within an array context
        See Also:
        JsonNumber
      • write

        JsonGenerator write(int value)
        Writes the specified value as a JSON number value within the current array context. The string new BigDecimal(value).toString() is used as the text value for writing.
        Parameters:
        value - a value to be written in current JSON array
        Returns:
        this generator
        Throws:
        JsonException - if an i/o error occurs (IOException would be cause of JsonException)
        JsonGenerationException - if this method is not called within an array context
      • write

        JsonGenerator write(long value)
        Writes the specified value as a JSON number value within the current array context. The string new BigDecimal(value).toString() is used as the text value for writing.
        Parameters:
        value - a value to be written in current JSON array
        Returns:
        this generator
        Throws:
        JsonException - if an i/o error occurs (IOException would be cause of JsonException)
        JsonGenerationException - if this method is not called within an array context
      • write

        JsonGenerator write(double value)
        Writes the specified value as a JSON number value within the current array context. The string BigDecimal.valueOf(value).toString() is used as the text value for writing.
        Parameters:
        value - a value to be written in current JSON array
        Returns:
        this generator
        Throws:
        JsonException - if an i/o error occurs (IOException would be cause of JsonException)
        JsonGenerationException - if this method is not called within an array context
        NumberFormatException - if the value is Not-a-Number(NaN) or infinity.
      • write

        JsonGenerator write(boolean value)
        Writes a JSON true or false value within the current array context. If value is true, this method writes the JSON true value, otherwise it writes the JSON false value.
        Parameters:
        value - a boolean value
        Returns:
        this generator
        Throws:
        JsonException - if an i/o error occurs (IOException would be cause of JsonException)
        JsonGenerationException - if this method is not called within an array context.
      • writeNull

        JsonGenerator writeNull()
        Writes a JSON null value within the current array context.
        Returns:
        this generator
        Throws:
        JsonException - if an i/o error occurs (IOException would be cause of JsonException)
        JsonGenerationException - if this method is not called within an array context
      • close

        void close()
        Closes this generator and frees any resources associated with it. This method closes the underlying output source.
        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface Closeable
        Throws:
        JsonException - if an i/o error occurs (IOException would be cause of JsonException)
        JsonGenerationException - if an incomplete JSON is generated
      • flush

        void flush()
        Flushes the underlying output source. If the generator has saved any characters in a buffer, writes them immediately to the underlying output source before flushing it.
        Specified by:
        flush in interface Flushable
        Throws:
        JsonException - if an i/o error occurs (IOException would be cause of JsonException)

Nederlandse vertaling

U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.

Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.

Bij voorbaat dank.

Document heeft de 11/06/2005 gemaakt, de laatste keer de 18/08/2025 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-javaee-rf-javax/json/stream/JsonGenerator.html

De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.

Referenties

  1. Bekijk - html-document Taal van het document:fr Manuel PHP : https://docs.oracle.com, JsonGenerator (Java(TM) EE 7 Specification APIs)

Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur van deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.