Skip to content

Commit

Permalink
Add CBOR support to AllEncompassingFormHttpMessageConverter
Browse files Browse the repository at this point in the history
  • Loading branch information
sdeleuze committed Mar 28, 2024
1 parent cf87441 commit db1010f
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.springframework.http.converter.FormHttpMessageConverter;
import org.springframework.http.converter.cbor.KotlinSerializationCborHttpMessageConverter;
import org.springframework.http.converter.cbor.MappingJackson2CborHttpMessageConverter;
import org.springframework.http.converter.json.GsonHttpMessageConverter;
import org.springframework.http.converter.json.JsonbHttpMessageConverter;
import org.springframework.http.converter.json.KotlinSerializationJsonHttpMessageConverter;
Expand All @@ -31,7 +32,8 @@

/**
* Extension of {@link org.springframework.http.converter.FormHttpMessageConverter},
* adding support for XML and JSON-based parts.
* adding support for XML, JSON, Smile, CBOR, Protobuf and Yaml based parts when
* related libraries are present in the classpath.
*
* @author Rossen Stoyanchev
* @author Juergen Hoeller
Expand All @@ -48,6 +50,8 @@ public class AllEncompassingFormHttpMessageConverter extends FormHttpMessageConv

private static final boolean jackson2SmilePresent;

private static final boolean jackson2CborPresent;

private static final boolean jackson2YamlPresent;

private static final boolean gsonPresent;
Expand All @@ -67,6 +71,7 @@ public class AllEncompassingFormHttpMessageConverter extends FormHttpMessageConv
ClassUtils.isPresent("com.fasterxml.jackson.core.JsonGenerator", classLoader);
jackson2XmlPresent = ClassUtils.isPresent("com.fasterxml.jackson.dataformat.xml.XmlMapper", classLoader);
jackson2SmilePresent = ClassUtils.isPresent("com.fasterxml.jackson.dataformat.smile.SmileFactory", classLoader);
jackson2CborPresent = ClassUtils.isPresent("com.fasterxml.jackson.dataformat.cbor.CBORFactory", classLoader);
jackson2YamlPresent = ClassUtils.isPresent("com.fasterxml.jackson.dataformat.yaml.YAMLFactory", classLoader);
gsonPresent = ClassUtils.isPresent("com.google.gson.Gson", classLoader);
jsonbPresent = ClassUtils.isPresent("jakarta.json.bind.Jsonb", classLoader);
Expand Down Expand Up @@ -103,6 +108,10 @@ else if (jsonbPresent) {
addPartConverter(new MappingJackson2SmileHttpMessageConverter());
}

if (jackson2CborPresent) {
addPartConverter(new MappingJackson2CborHttpMessageConverter());
}

if (jackson2YamlPresent) {
addPartConverter(new MappingJackson2YamlHttpMessageConverter());
}
Expand Down

0 comments on commit db1010f

Please sign in to comment.