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

net.aequologica.neo.shakuntala.EventCodecJsonImpl Maven / Gradle / Ivy

There is a newer version: 0.6.7
Show newest version
package net.aequologica.neo.shakuntala;

import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL;

import java.io.IOException;
import java.io.StringWriter;

import javax.inject.Named;

import org.eclipse.aether.RepositoryEvent;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

@Named(value = "jackson")
public class EventCodecJsonImpl implements EventCodec {

    final private ObjectMapper mapper;

    public EventCodecJsonImpl() {
        super();
        this.mapper = new ObjectMapper();
        this.mapper.setSerializationInclusion(NON_NULL);
    }

    @Override
    public Event valueOf(String str) throws IOException {
        return mapper.readValue(str, new TypeReference() {});
    }

    @Override
    public String toString(Event event) throws IOException {
        StringWriter sw = new StringWriter();
        Object object = event.getObject();
        if (object instanceof RepositoryEvent) {
            RepositoryEvent repositoryEvent = (RepositoryEvent)object;
            if (repositoryEvent.getArtifact() != null) {
              event = new Event2(event.getKey(), event.getValue(), event.getLevel(), event.getObject(), repositoryEvent.getArtifact().toString());
            }
        }
        mapper.writeValue(sw, event);
        return sw.toString();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy