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

com.uid2.shared.store.parser.ServiceLinkParser Maven / Gradle / Ivy

package com.uid2.shared.store.parser;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;

import com.uid2.shared.model.ServiceLink;
import com.uid2.shared.util.Mapper;

import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.stream.Collectors;

public class ServiceLinkParser implements Parser> {

    private static final ObjectMapper OBJECT_MAPPER = Mapper.getInstance();

    static {
        OBJECT_MAPPER.enable(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE);
    }

    @Override
    public ParsingResult> deserialize(InputStream inputStream) throws IOException {
        ServiceLink[] serviceLinks = OBJECT_MAPPER.readValue(inputStream, ServiceLink[].class);
        Map serviceLinkList = Arrays.stream(serviceLinks).collect(Collectors.toMap(s -> (s.getServiceId() + "_" + s.getLinkId()), s -> s));
        return new ParsingResult<>(serviceLinkList, serviceLinkList.size());
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy