Record Class GeneratorContext
java.lang.Object
java.lang.Record
io.github.toberocat.guiengine.utils.GeneratorContext
public record GeneratorContext(@NotNull com.fasterxml.jackson.core.JsonGenerator generator)
extends Record
GeneratorContext is a utility class that encapsulates a JsonGenerator instance to assist in writing JSON data.
Created: 14.07.2023 Author: Tobias Madlberger (Tobias)
-
Constructor Summary
ConstructorsConstructorDescriptionGeneratorContext
(@NotNull com.fasterxml.jackson.core.JsonGenerator generator) Creates an instance of aGeneratorContext
record class. -
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
Indicates whether some other object is "equal to" this one.@NotNull com.fasterxml.jackson.core.JsonGenerator
Retrieves the JsonGenerator associated with this context.final int
hashCode()
Returns a hash code value for this object.final String
toString()
Returns a string representation of this record class.void
writeBooleanField
(@NotNull String fieldName, boolean value) Writes a JSON boolean field with the specified field name and value to the generator.void
writeFunctionField
(@NotNull String fieldName, @NotNull List<GuiFunction> functions) void
writeNumberField
(@NotNull String fieldName, double value) Writes a JSON number field with the specified field name and value to the generator.void
writeNumberField
(@NotNull String fieldName, float value) Writes a JSON number field with the specified field name and value to the generator.void
writeNumberField
(@NotNull String fieldName, int value) Writes a JSON number field with the specified field name and value to the generator.void
writeNumberField
(@NotNull String fieldName, long value) Writes a JSON number field with the specified field name and value to the generator.void
writePOJOField
(@NotNull String fieldName, Object value) Writes a JSON POJO field with the specified field name and value to the generator.void
Writes raw JSON data to the generator.void
writeStringField
(@NotNull String fieldName, @NotNull String value) Writes a JSON string field with the specified field name and value to the generator.
-
Constructor Details
-
GeneratorContext
public GeneratorContext(@NotNull @NotNull com.fasterxml.jackson.core.JsonGenerator generator) Creates an instance of aGeneratorContext
record class.- Parameters:
generator
- the value for thegenerator
record component
-
-
Method Details
-
generator
@NotNull public @NotNull com.fasterxml.jackson.core.JsonGenerator generator()Retrieves the JsonGenerator associated with this context.- Returns:
- The JsonGenerator instance.
-
writeStringField
public void writeStringField(@NotNull @NotNull String fieldName, @NotNull @NotNull String value) throws IOException Writes a JSON string field with the specified field name and value to the generator.- Parameters:
fieldName
- The name of the JSON field to write.value
- The string value to write for the field.- Throws:
IOException
- If an I/O error occurs while writing to the generator.
-
writeNumberField
Writes a JSON number field with the specified field name and value to the generator.- Parameters:
fieldName
- The name of the JSON field to write.value
- The integer value to write for the field.- Throws:
IOException
- If an I/O error occurs while writing to the generator.
-
writeNumberField
Writes a JSON number field with the specified field name and value to the generator.- Parameters:
fieldName
- The name of the JSON field to write.value
- The integer value to write for the field.- Throws:
IOException
- If an I/O error occurs while writing to the generator.
-
writeNumberField
Writes a JSON number field with the specified field name and value to the generator.- Parameters:
fieldName
- The name of the JSON field to write.value
- The integer value to write for the field.- Throws:
IOException
- If an I/O error occurs while writing to the generator.
-
writeNumberField
Writes a JSON number field with the specified field name and value to the generator.- Parameters:
fieldName
- The name of the JSON field to write.value
- The integer value to write for the field.- Throws:
IOException
- If an I/O error occurs while writing to the generator.
-
writeBooleanField
Writes a JSON boolean field with the specified field name and value to the generator.- Parameters:
fieldName
- The name of the JSON field to write.value
- The boolean value to write for the field.- Throws:
IOException
- If an I/O error occurs while writing to the generator.
-
writePOJOField
Writes a JSON POJO field with the specified field name and value to the generator.- Parameters:
fieldName
- The name of the JSON field to write.value
- The object value to write for the field.- Throws:
IOException
- If an I/O error occurs while writing to the generator.
-
writeFunctionField
public void writeFunctionField(@NotNull @NotNull String fieldName, @NotNull @NotNull List<GuiFunction> functions) throws IOException - Throws:
IOException
-
writeRaw
Writes raw JSON data to the generator.- Parameters:
raw
- The raw JSON data to write.- Throws:
IOException
- If an I/O error occurs while writing to the generator.
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object)
.
-