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

com.essec.microservices.serializer.LinkSerializer Maven / Gradle / Ivy

Go to download

Shared configuration and tools. This project contains a custom spring boot module to facilitate new api project developpement startup process.

There is a newer version: 1.0.42
Show newest version
package com.essec.microservices.serializer;

import java.io.IOException;
import java.util.Objects;

import javax.ws.rs.core.Link;

import org.springframework.boot.jackson.JsonComponent;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

@JsonComponent
public class LinkSerializer extends JsonSerializer{

    @Override
    public void serialize(Link link, JsonGenerator jg, SerializerProvider sp) 
            throws IOException, JsonProcessingException {
        jg.writeStartObject();
        jg.writeStringField("uri", Objects.toString(link.getUri(), ""));
        jg.writeStringField("title", Objects.toString(link.getTitle(), ""));
        jg.writeStringField("rel", Objects.toString(link.getRel(), ""));
        jg.writeStringField("type", Objects.toString(link.getType(), ""));
        jg.writeEndObject();
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy