net.aequologica.neo.shakuntala.EventCodecRepositoryEventImpl Maven / Gradle / Ivy
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.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
@Named(value = "repositoryEventCodec")
public class EventCodecRepositoryEventImpl implements EventCodec {
final private ObjectMapper mapper;
public EventCodecRepositoryEventImpl() {
super();
this.mapper = new ObjectMapper();
this.mapper.setSerializationInclusion(NON_NULL);
this.mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
this.mapper.enable(SerializationFeature.INDENT_OUTPUT);
}
@Override
public Event valueOf(String str) throws IOException {
throw new UnsupportedOperationException();
}
@Override
public String toString(Event event) throws IOException {
StringWriter sw = new StringWriter();
Object object = event.getObject();
if (object instanceof RepositoryEvent) {
RepositoryEvent repositoryEvent = (RepositoryEvent)object;
mapper.writeValue(sw, repositoryEvent.getArtifact());
}
return sw.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy