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 aGeneratorContextrecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.@NotNull com.fasterxml.jackson.core.JsonGeneratorRetrieves the JsonGenerator associated with this context.final inthashCode()Returns a hash code value for this object.final StringtoString()Returns a string representation of this record class.voidwriteBooleanField(@NotNull String fieldName, boolean value) Writes a JSON boolean field with the specified field name and value to the generator.voidwriteFunctionField(@NotNull String fieldName, @NotNull List<GuiFunction> functions) voidwriteNumberField(@NotNull String fieldName, double value) Writes a JSON number field with the specified field name and value to the generator.voidwriteNumberField(@NotNull String fieldName, float value) Writes a JSON number field with the specified field name and value to the generator.voidwriteNumberField(@NotNull String fieldName, int value) Writes a JSON number field with the specified field name and value to the generator.voidwriteNumberField(@NotNull String fieldName, long value) Writes a JSON number field with the specified field name and value to the generator.voidwritePOJOField(@NotNull String fieldName, Object value) Writes a JSON POJO field with the specified field name and value to the generator.voidWrites raw JSON data to the generator.voidwriteStringField(@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 aGeneratorContextrecord class.- Parameters:
generator- the value for thegeneratorrecord 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).
-