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

org.opendaylight.jsonrpc.dom.codec.JsonReaderAdapter Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2020 Lumina Networks, Inc. All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.jsonrpc.dom.codec;

import com.google.common.annotations.Beta;
import com.google.gson.JsonElement;
import com.google.gson.stream.JsonReader;
import java.io.Reader;
import java.io.StringReader;
import org.eclipse.jdt.annotation.NonNull;

/**
 * Helper class to eliminate repeated new JsonReader(new StringReader(json.toString())).
 *
 * @author Richard Kosegi
 * @since Feb 22, 2020
 */
@Beta
public final class JsonReaderAdapter extends JsonReader {
    private JsonReaderAdapter(Reader in) {
        super(in);
    }

    /**
     * Create new instance of {@link JsonReader} using provided {@link JsonElement}.
     *
     * @param json {@link JsonElement} to create reader from.
     * @return new {@link JsonReader} instance.
     */
    public static JsonReader from(@NonNull JsonElement json) {
        return new JsonReaderAdapter(new StringReader(json.toString()));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy