From 62a8c3bf77d39301c5d9b7dc77bfa53426a3fdcc Mon Sep 17 00:00:00 2001 From: Khalid Qarryzada Date: Fri, 20 Feb 2026 13:18:41 -0800 Subject: [PATCH] Update ErrorResponse serialization. Updated the ErrorResponse class to serialize into a form that is more consistent with the example JSON objects presented in RFC 7644. Reviewer: vyhhuang Reviewer: dougbulkley JiraIssue: DS-51249 --- CHANGELOG.md | 3 ++ .../scim2/common/messages/ErrorResponse.java | 2 ++ .../scim2/common/ErrorResponseTest.java | 34 +++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd070c42..373d15ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ This project adheres to [Semantic Versioning](https://semver.org/). ## v5.0.1 - TBD Updated Jackson to 2.20.1. +Updated `ErrorResponse.java` to print attributes in an order that is more consistent with the +example JSON objects presented in RFC 7644. Now, `status` is the last attribute printed. + ## v5.0.0 - 2025-Dec-15 For consistency with other open source Ping Identity software, the UnboundID SCIM 2 SDK for Java is now available under the terms of the Apache License (version 2.0). For legacy compatibility, the diff --git a/scim2-sdk-common/src/main/java/com/unboundid/scim2/common/messages/ErrorResponse.java b/scim2-sdk-common/src/main/java/com/unboundid/scim2/common/messages/ErrorResponse.java index efd5195a..c24f09fa 100644 --- a/scim2-sdk-common/src/main/java/com/unboundid/scim2/common/messages/ErrorResponse.java +++ b/scim2-sdk-common/src/main/java/com/unboundid/scim2/common/messages/ErrorResponse.java @@ -34,6 +34,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.unboundid.scim2.common.annotations.NotNull; @@ -85,6 +86,7 @@ */ @Schema(id="urn:ietf:params:scim:api:messages:2.0:Error", name="Error Response", description = "SCIM 2.0 Error Response") +@JsonPropertyOrder({"schemas", "scimType", "detail", "status"}) public class ErrorResponse extends BaseScimResource { @Nullable diff --git a/scim2-sdk-common/src/test/java/com/unboundid/scim2/common/ErrorResponseTest.java b/scim2-sdk-common/src/test/java/com/unboundid/scim2/common/ErrorResponseTest.java index 6194d58f..aea531ca 100644 --- a/scim2-sdk-common/src/test/java/com/unboundid/scim2/common/ErrorResponseTest.java +++ b/scim2-sdk-common/src/test/java/com/unboundid/scim2/common/ErrorResponseTest.java @@ -39,6 +39,7 @@ import com.unboundid.scim2.common.utils.SchemaUtils; import org.testng.annotations.Test; +import static org.assertj.core.api.Assertions.assertThat; import static org.testng.Assert.assertEquals; /** @@ -122,4 +123,37 @@ public void testDeserializationAndSerializationWithNumberStatus() readValue(serializedString); assertEquals(errorResponse, deserializedErrorResponse); } + + /** + * Ensures that serialized ErrorResponse objects match the form presented in + * RFC 7644. + */ + @Test + public void testSerialization() throws Exception + { + // Use a JSON string from the RFC with all fields populated. + String json = """ + { + "schemas": ["urn:ietf:params:scim:api:messages:2.0:Error"], + "scimType": "invalidSyntax", + "detail": "Request is unparsable, syntactically incorrect, or violates schema.", + "status": "400" + }"""; + String expectedJSON = JsonUtils.getObjectReader().readTree(json) + .toPrettyString(); + + // Construct the same data in object form. When the object is printed as a + // string, it should match the expected output. + ErrorResponse errorResponse = new ErrorResponse(400); + errorResponse.setScimType("invalidSyntax"); + errorResponse.setDetail( + "Request is unparsable, syntactically incorrect, or violates schema."); + assertThat(errorResponse.toString()).isEqualTo(expectedJSON); + + // The string formatting should also match when the error originates from + // an exception object. + BadRequestException e = BadRequestException.invalidSyntax( + "Request is unparsable, syntactically incorrect, or violates schema."); + assertThat(e.getScimError().toString()).isEqualTo(expectedJSON); + } }