#867 - Reenable default encoders and encoders.

Thanks to https://github.com/spring-projects/spring-framework/issues/22612, Spring HATEAOAS no longer has to disable the default registry of encoders and decoders to get its custom components to work.

Related issues: #885, https://github.com/spring-projects/spring-framework/issues/22612
This commit is contained in:
Greg Turnquist
2019-03-21 14:39:19 -05:00
parent 110bf6280a
commit fc3767b90b

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.hateoas.config;
import lombok.RequiredArgsConstructor;
@@ -7,10 +22,8 @@ import java.util.Collection;
import java.util.List;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.codec.CharSequenceEncoder;
import org.springframework.core.codec.Decoder;
import org.springframework.core.codec.Encoder;
import org.springframework.core.codec.StringDecoder;
import org.springframework.hateoas.config.EnableHypermediaSupport.HypermediaType;
import org.springframework.http.codec.json.Jackson2JsonDecoder;
import org.springframework.http.codec.json.Jackson2JsonEncoder;
@@ -52,15 +65,11 @@ public class WebClientConfigurer {
decoders.add(new Jackson2JsonDecoder(objectMapper, mimeTypes));
});
encoders.add(CharSequenceEncoder.allMimeTypes());
decoders.add(StringDecoder.allMimeTypes());
return ExchangeStrategies.builder().codecs(clientCodecConfigurer -> {
encoders.forEach(encoder -> clientCodecConfigurer.customCodecs().encoder(encoder));
decoders.forEach(decoder -> clientCodecConfigurer.customCodecs().decoder(decoder));
clientCodecConfigurer.registerDefaults(false);
}).build();
}