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

org.apache.syncope.common.lib.jaxb.XmlGenericMapAdapter Maven / Gradle / Ivy

There is a newer version: 2.1.14
Show newest version
/*
 * Copyright 2011 John Yeary .
 * Copyright 2011 Bluelotus Software, LLC.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.syncope.common.lib.jaxb;

import java.util.HashMap;
import java.util.Map;
import javax.xml.bind.annotation.adapters.XmlAdapter;

public class XmlGenericMapAdapter extends XmlAdapter, Map> {

    @Override
    public Map unmarshal(final GenericMapType v) throws Exception {
        Map map = new HashMap<>();

        for (GenericMapEntryType mapEntryType : v.getEntry()) {
            map.put(mapEntryType.getKey(), mapEntryType.getValue());
        }

        return map;
    }

    @Override
    public GenericMapType marshal(final Map v) throws Exception {
        GenericMapType mapType = new GenericMapType<>();

        for (Map.Entry entry : v.entrySet()) {
            GenericMapEntryType mapEntryType = new GenericMapEntryType<>();
            mapEntryType.setKey(entry.getKey());
            mapEntryType.setValue(entry.getValue());
            mapType.getEntry().add(mapEntryType);
        }

        return mapType;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy