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

shade.com.alibaba.fastjson2.function.impl.ToLong Maven / Gradle / Ivy

There is a newer version: 1.3.7
Show newest version
package com.alibaba.fastjson2.function.impl;

import com.alibaba.fastjson2.JSONException;

import java.util.function.Function;

public class ToLong
        implements Function {
    final Long defaultValue;

    public ToLong(Long defaultValue) {
        this.defaultValue = defaultValue;
    }

    @Override
    public Object apply(Object o) {
        if (o == null) {
            return defaultValue;
        }

        if (o instanceof Boolean) {
            return (Boolean) o ? 1L : 0L;
        }

        if (o instanceof Number) {
            return ((Number) o).longValue();
        }

        throw new JSONException("can not cast to Long " + o.getClass());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy