-
Notifications
You must be signed in to change notification settings - Fork 38.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ProblemDetail XML support via Jackson
Closes gh-29927
- Loading branch information
1 parent
9c0b28f
commit e5ff549
Showing
11 changed files
with
191 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...b/src/main/java/org/springframework/http/converter/json/ProblemDetailJacksonXmlMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 2002-2023 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.http.converter.json; | ||
|
||
import java.net.URI; | ||
import java.util.Map; | ||
|
||
import com.fasterxml.jackson.annotation.JsonAnyGetter; | ||
import com.fasterxml.jackson.annotation.JsonAnySetter; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; | ||
|
||
import org.springframework.lang.Nullable; | ||
|
||
import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY; | ||
|
||
/** | ||
* Intended to be identical to {@link ProblemDetailJacksonMixin} but for used | ||
* instead of it when jackson-dataformat-xml is on the classpath. Customizes the | ||
* XML root element name and adds namespace information. | ||
* | ||
* <p>Note: Unfortunately, we cannot just use {@code JsonRootName} to specify | ||
* the namespace since that is not inherited by fields of the class. This is | ||
* why we need a dedicated mixin for use when jackson-dataformat-xml is on the | ||
* classpath. For more details, see | ||
* <a href="https://github.com/FasterXML/jackson-dataformat-xml/issues/355">FasterXML/jackson-dataformat-xml#355</a>. | ||
* | ||
* @author Rossen Stoyanchev | ||
* @since 6.0.5 | ||
*/ | ||
@JsonInclude(NON_EMPTY) | ||
@JacksonXmlRootElement(localName = "problem", namespace = "urn:ietf:rfc:7807") | ||
public interface ProblemDetailJacksonXmlMixin { | ||
|
||
@JacksonXmlProperty(namespace = "urn:ietf:rfc:7807") | ||
URI getType(); | ||
|
||
@JacksonXmlProperty(namespace = "urn:ietf:rfc:7807") | ||
String getTitle(); | ||
|
||
@JacksonXmlProperty(namespace = "urn:ietf:rfc:7807") | ||
int getStatus(); | ||
|
||
@JacksonXmlProperty(namespace = "urn:ietf:rfc:7807") | ||
String getDetail(); | ||
|
||
@JacksonXmlProperty(namespace = "urn:ietf:rfc:7807") | ||
URI getInstance(); | ||
|
||
@JsonAnySetter | ||
void setProperty(String name, @Nullable Object value); | ||
|
||
@JsonAnyGetter | ||
@JacksonXmlProperty(namespace = "urn:ietf:rfc:7807") | ||
Map<String, Object> getProperties(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters