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

com.powsybl.openreac.parameters.input.json.OpenReacAlgoParamDeserializer Maven / Gradle / Ivy

There is a newer version: 0.8.0
Show newest version
/**
 * Copyright (c) 2023, RTE (http://www.rte-france.com)
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package com.powsybl.openreac.parameters.input.json;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.powsybl.openreac.parameters.input.algo.OpenReacAlgoParam;
import com.powsybl.openreac.parameters.input.algo.OpenReacAlgoParamImpl;

import java.io.IOException;

/**
 * @author Geoffroy Jamgotchian 
 */
public class OpenReacAlgoParamDeserializer extends StdDeserializer {

    public OpenReacAlgoParamDeserializer() {
        super(OpenReacAlgoParam.class);
    }

    @Override
    public OpenReacAlgoParam deserialize(JsonParser parser, DeserializationContext deserializationContext) throws IOException {
        String name = null;
        String value = null;
        while (parser.nextToken() != JsonToken.END_OBJECT) {
            switch (parser.getCurrentName()) {
                case "name":
                    parser.nextToken();
                    name = parser.getText();
                    break;
                case "value":
                    parser.nextToken();
                    value = parser.getText();
                    break;
                default:
                    throw new IllegalStateException("Unexpected field: " + parser.getCurrentName());
            }
        }
        return new OpenReacAlgoParamImpl(name, value);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy