All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jsoniter.fuzzy.MaybeEmptyArrayDecoder Maven / Gradle / Ivy

Go to download

jsoniter (json-iterator) is fast and flexible JSON parser available in Java and Go

The newest version!
package com.jsoniter.fuzzy;

import com.jsoniter.JsonIterator;
import com.jsoniter.ValueType;
import com.jsoniter.spi.Binding;
import com.jsoniter.spi.Decoder;

import java.io.IOException;

public class MaybeEmptyArrayDecoder implements Decoder {

    private Binding binding;

    public MaybeEmptyArrayDecoder(Binding binding) {
        this.binding = binding;
    }

    @Override
    public Object decode(JsonIterator iter) throws IOException {
        if (iter.whatIsNext() == ValueType.ARRAY) {
            if (iter.readArray()) {
                throw iter.reportError("MaybeEmptyArrayDecoder", "this field is object. if input is array, it can only be empty");
            } else {
                // empty array parsed as null
                return null;
            }
        } else {
            return iter.read(binding.valueTypeLiteral);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy