Package net.commoble.databuddy.codec

# Class WriteFieldsFirstOps<T>

java.lang.Object
net.minecraft.resources.DelegatingOps<T>
net.commoble.databuddy.codec.WriteFieldsFirstOps<T>

All Implemented Interfaces:
  `com.mojang.serialization.DynamicOps<T>`

public class WriteFieldsFirstOps<T> extends net.minecraft.resources.DelegatingOps<T>

Delegating DynamicOps that, when serializing data, serializes specified fields in a given order before serializing any other fields. This may be helpful when writing human-readable data, such as json files.

As of 1.19, `DataProvider.saveStable(net.minecraft.data.CachedOutput, net.minecraft.core.HolderLookup.Provider, com.mojang.serialization.Codec<T>, T, java.nio.file.Path)` now automatically places "type" and "parent" fields at the top of jsons, making this class no longer necessary for the use case of datagenerating jsons with those fields.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final WriteFieldsFirstOps<com.google.gson.JsonElement>`
`TYPE_FIRST_JSON_OPS`
JsonOps that writes the "type" field first when serializing records.
Helpful when serializing type-dispatched json objects.
(type field goes at the top instead of the bottom, making the json easier to read)

### Fields inherited from class net.minecraft.resources.DelegatingOps

`delegate`

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`WriteFieldsFirstOps(com.mojang.serialization.DynamicOps<T> delegate, String... priorityFields)`

## Method Summary

Modifier and Type
Method
Description
`T`
`createMap(Stream<com.mojang.datafixers.util.Pair<T,T>> fields)`
`com.mojang.serialization.RecordBuilder<T>`
`mapBuilder()`
`static <T> WriteFieldsFirstOps<T>`
`of(com.mojang.serialization.DynamicOps<T> delegate, String... priorityFields)`

### Methods inherited from class net.minecraft.resources.DelegatingOps

`compressMaps, convertTo, createBoolean, createByte, createByteList, createDouble, createFloat, createInt, createIntList, createList, createLong, createLongList, createMap, createNumeric, createShort, createString, empty, emptyList, emptyMap, getBooleanValue, getByteBuffer, getIntStream, getList, getLongStream, getMap, getMapEntries, getMapValues, getNumberValue, getStream, getStringValue, listBuilder, mergeToList, mergeToList, mergeToMap, mergeToMap, mergeToMap, mergeToPrimitive, remove`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface com.mojang.serialization.DynamicOps

`convertList, convertMap, get, getGeneric, getNumberValue, set, update, updateGeneric, withDecoder, withEncoder, withParser`

## Field Details

### TYPE_FIRST_JSON_OPS

public static final WriteFieldsFirstOps<com.google.gson.JsonElement> TYPE_FIRST_JSON_OPS
JsonOps that writes the "type" field first when serializing records.
Helpful when serializing type-dispatched json objects.
(type field goes at the top instead of the bottom, making the json easier to read)

## Constructor Details

### WriteFieldsFirstOps

protected WriteFieldsFirstOps(com.mojang.serialization.DynamicOps<T> delegate, String... priorityFields)

Parameters:
  `delegate` - DynamicOps to delegate to
  `priorityFields` - String names of the fields to keep at the top of the serialized object

## Method Details

### of

public static <T> WriteFieldsFirstOps<T> of(com.mojang.serialization.DynamicOps<T> delegate, String... priorityFields)

Type Parameters:
  `T` - Base class of serialized objects, e.g. nbt Tag or JsonElement
Parameters:
  `delegate` - The actual DynamicOps to delegate to
  `priorityFields` - Sequence of (optional) fields to write first when writing maplike objects
Returns:
  DynamicOps that, when serializing maplike objects, serializes the specified fields first (when present) before serializing other fields in the object. Any fields in the object present in the priorityFields sequence will be written first in the specified order, followed by any fields not-present-in-priorityFields in the usual order.

### createMap

public T createMap(Stream<com.mojang.datafixers.util.Pair<T,T>> fields)

Specified by:
  `createMap` in interface `com.mojang.serialization.DynamicOps<T>`
Overrides:
  `createMap` in class `net.minecraft.resources.DelegatingOps<T>`

### mapBuilder

public com.mojang.serialization.RecordBuilder<T> mapBuilder()

Specified by:
  `mapBuilder` in interface `com.mojang.serialization.DynamicOps<T>`
Overrides:
  `mapBuilder` in class `net.minecraft.resources.DelegatingOps<T>`