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

org.zalando.riptide.SerializationPlugin Maven / Gradle / Ivy

There is a newer version: 4.0.0
Show newest version
package org.zalando.riptide;

import lombok.AllArgsConstructor;
import org.springframework.http.HttpOutputMessage;
import org.zalando.riptide.RequestArguments.Entity;

import java.io.IOException;

@AllArgsConstructor
final class SerializationPlugin implements Plugin {

    private final MessageWriter writer;

    @Override
    public RequestExecution aroundSerialization(final RequestExecution execution) {
        return arguments -> execution.execute(arguments.getEntity() == null ?
                arguments.withEntity(new SerializingEntity(arguments)) :
                arguments);
    }

    @AllArgsConstructor
    private class SerializingEntity implements Entity {

        private final RequestArguments arguments;

        @Override
        public void writeTo(final HttpOutputMessage message) throws IOException {
            writer.write(message, arguments);
        }

        @Override
        public boolean isEmpty() {
            return arguments.getBody() == null;
        }

    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy