BodyInserters.fromObject is deprecated, what is the alternative?

Viewed 1649

Helllo. I am trying to use Spring webclient to send post requests and fill the body with an object. But I receive the following " 'fromObject(T)' is deprecate". What is the alternative then ?

WebClient.post()
            .uri("example.com")
            .body(BodyInserters.fromObject(newObject);
1 Answers

The javadoc clearly says to use fromValue.

public static <T> BodyInserter<T,ReactiveHttpOutputMessage> fromValue(T body)

Inserter to write the given value. Alternatively, consider using the bodyValue(Object) shortcuts on WebClient and ServerResponse.

Type Parameters:

T - the type of the body

Parameters: body - the value to write

Returns:

the inserter to write a single value

Throws:

IllegalArgumentException - if body is a Publisher or an instance of a type supported by ReactiveAdapterRegistry.getSharedInstance(), for which fromPublisher(Publisher, Class) or fromProducer(Object, Class) should be used.

Related