Package commoble.databuddy.codec

# Class NullableFieldCodec<VALUE>

java.lang.Object
com.mojang.serialization.CompressorHolder
com.mojang.serialization.MapCodec<Optional<A>>
com.mojang.serialization.codecs.OptionalFieldCodec<VALUE>
commoble.databuddy.codec.NullableFieldCodec<VALUE>

All Implemented Interfaces:
  `com.mojang.serialization.Compressable`, `com.mojang.serialization.Keyable`, `com.mojang.serialization.MapDecoder<Optional<VALUE>>`, `com.mojang.serialization.MapEncoder<Optional<VALUE>>`

public class NullableFieldCodec<VALUE> extends com.mojang.serialization.codecs.OptionalFieldCodec<VALUE>

Similar to OptionalFieldCodec, but *only* permits absent values. OptionalFieldCodec silently catches any parsing error-results and returns an empty optional in such cases.

NullableFieldCodec returns an empty optional when it encounters absent values, but returns error results if encounters any other decoding issues.

## Nested Class Summary

## Nested classes/interfaces inherited from class com.mojang.serialization.MapCodec

`com.mojang.serialization.MapCodec.MapCodecCodec<A extends Object>, com.mojang.serialization.MapCodec.ResultFunction<A extends Object>`

## Nested classes/interfaces inherited from interface com.mojang.serialization.MapDecoder

`com.mojang.serialization.MapDecoder.Implementation<A extends Object>`

## Nested classes/interfaces inherited from interface com.mojang.serialization.MapEncoder

`com.mojang.serialization.MapEncoder.Implementation<A extends Object>`

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`NullableFieldCodec​(String name, com.mojang.serialization.Codec<VALUE> elementCodec)`

## Method Summary

Modifier and Type
Method
Description
`<T> com.mojang.serialization.DataResult<Optional<VALUE>>`
`decode​(com.mojang.serialization.DynamicOps<T> ops, com.mojang.serialization.MapLike<T> input)`
`static <VALUE> com.mojang.serialization.MapCodec<VALUE>`
`makeDefaultableField​(String name, com.mojang.serialization.Codec<VALUE> elementCodec, VALUE defaultValue)`
As with makeOptional field, but decodes values directly to the given type instead of wrapping in an optional.
`static <VALUE> com.mojang.serialization.MapCodec<Optional<VALUE>>`
`makeOptionalField​(String name, com.mojang.serialization.Codec<VALUE> elementCodec)`
Creates a field codec useable in RecordCodecBuilder for a field that permits absent or null values.

### Methods inherited from class com.mojang.serialization.codecs.OptionalFieldCodec

`encode, equals, hashCode, keys, toString`

### Methods inherited from class com.mojang.serialization.MapCodec

`codec, dependent, deprecated, fieldOf, flatXmap, forGetter, mapResult, of, of, orElse, orElse, orElse, orElseGet, orElseGet, orElseGet, setPartial, stable, unit, unit, withLifecycle, xmap`

### Methods inherited from class com.mojang.serialization.CompressorHolder

`compressor`

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

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

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

`ap, compressedDecode, compressor, decoder, flatMap, map`

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

`comap, compressedBuilder, compressor, encoder, flatComap`

## Constructor Details

### NullableFieldCodec

protected NullableFieldCodec​(String name, com.mojang.serialization.Codec<VALUE> elementCodec)

## Method Details

### makeOptionalField

public static <VALUE> com.mojang.serialization.MapCodec<Optional<VALUE>> makeOptionalField​(String name, com.mojang.serialization.Codec<VALUE> elementCodec)
Creates a field codec useable in RecordCodecBuilder for a field that permits absent or null values. Decodes absent or null values as an empty optional. Empty optionals are not encoded (resulting in an absent value). Note that attempting to encode a null value (rather than an empty optional) results in a NullPointerException.

Type Parameters:
  `VALUE` - The type of the field's value
Parameters:
  `name` - The name of the field
  `elementCodec` - The codec to delegate to for encoding/decoding the field's values
Returns:
  A codec for a field that permits absent or null values

### makeDefaultableField

public static <VALUE> com.mojang.serialization.MapCodec<VALUE> makeDefaultableField​(String name, com.mojang.serialization.Codec<VALUE> elementCodec, VALUE defaultValue)
As with makeOptional field, but decodes values directly to the given type instead of wrapping in an optional. Absent or null values are decoded as the given default value.

Type Parameters:
  `VALUE` - The type of the field's value
Parameters:
  `name` - The name of the field
  `elementCodec` - The codec to delegate to for encoding/decoding the field's values
  `defaultValue` - The value that will be decoded if the field is null or absent
Returns:
  A codec for a field that permits absent or null values

### decode

public <T> com.mojang.serialization.DataResult<Optional<VALUE>> decode​(com.mojang.serialization.DynamicOps<T> ops, com.mojang.serialization.MapLike<T> input)

Specified by:
  `decode` in interface `com.mojang.serialization.MapDecoder<VALUE>`
Overrides:
  `decode` in class `com.mojang.serialization.codecs.OptionalFieldCodec<VALUE>`