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

com.powsybl.action.json.PhaseTapChangerTapPositionActionBuilderDeserializer Maven / Gradle / Ivy

The 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/.
 * SPDX-License-Identifier: MPL-2.0
 */
package com.powsybl.action.json;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.powsybl.action.PhaseTapChangerTapPositionActionBuilder;
import com.powsybl.commons.json.JsonUtil;
import com.powsybl.action.PhaseTapChangerTapPositionAction;

import java.io.IOException;

/**
 * @author Etienne Lesot {@literal }
 */
public class PhaseTapChangerTapPositionActionBuilderDeserializer
    extends AbstractTapChangerTapPositionActionBuilderDeserializer {

    public PhaseTapChangerTapPositionActionBuilderDeserializer() {
        super(PhaseTapChangerTapPositionActionBuilder.class);
    }

    @Override
    public PhaseTapChangerTapPositionActionBuilder deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
        PhaseTapChangerTapPositionActionBuilder builder = new PhaseTapChangerTapPositionActionBuilder();
        String version = (String) deserializationContext.getAttribute(ActionListDeserializer.VERSION);
        JsonUtil.parsePolymorphicObject(jsonParser, name -> {
            boolean found = deserializeCommonAttributes(jsonParser, builder, name, version);
            if (found) {
                return true;
            }
            if (name.equals("type")) {
                String type = jsonParser.nextTextValue();
                if (!PhaseTapChangerTapPositionAction.NAME.equals(type)) {
                    throw JsonMappingException.from(jsonParser, "Expected type :" + PhaseTapChangerTapPositionAction.NAME + " got : " + type);
                }
                return true;
            }
            return false;
        });
        checkFields(builder, jsonParser);
        return builder;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy