Skip to content

Commit acb49b9

Browse files
committed
Merge branch '1.2.x' into 1.3.x
Closes gh-1683
2 parents 14f38e1 + 72d7fb1 commit acb49b9

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/jackson2/OAuth2AuthorizationServerJackson2Module.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
* <li>{@link DurationMixin}</li>
4444
* <li>{@link JwsAlgorithmMixin}</li>
4545
* <li>{@link OAuth2TokenFormatMixin}</li>
46+
* <li>{@link StringArrayMixin}</li>
4647
* </ul>
4748
*
4849
* If not already enabled, default typing will be automatically enabled as type info is
@@ -66,6 +67,7 @@
6667
* @see DurationMixin
6768
* @see JwsAlgorithmMixin
6869
* @see OAuth2TokenFormatMixin
70+
* @see StringArrayMixin
6971
*/
7072
public class OAuth2AuthorizationServerJackson2Module extends SimpleModule {
7173

@@ -88,6 +90,7 @@ public void setupModule(SetupContext context) {
8890
context.setMixInAnnotations(SignatureAlgorithm.class, JwsAlgorithmMixin.class);
8991
context.setMixInAnnotations(MacAlgorithm.class, JwsAlgorithmMixin.class);
9092
context.setMixInAnnotations(OAuth2TokenFormat.class, OAuth2TokenFormatMixin.class);
93+
context.setMixInAnnotations(String[].class, StringArrayMixin.class);
9194
}
9295

9396
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2020-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.security.oauth2.server.authorization.jackson2;
17+
18+
import com.fasterxml.jackson.annotation.JsonCreator;
19+
import com.fasterxml.jackson.annotation.JsonTypeInfo;
20+
21+
/**
22+
* This mixin class is used to serialize/deserialize {@link String} array.
23+
*
24+
* @author Nikola Jovanovic
25+
* @since 1.2.6
26+
* @see String
27+
*/
28+
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
29+
abstract class StringArrayMixin {
30+
31+
@JsonCreator
32+
StringArrayMixin(String[] array) {
33+
}
34+
35+
}

oauth2-authorization-server/src/test/java/org/springframework/security/oauth2/server/authorization/jackson2/OAuth2AuthorizationServerJackson2ModuleTests.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2022 the original author or authors.
2+
* Copyright 2020-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -43,6 +43,9 @@ public class OAuth2AuthorizationServerJackson2ModuleTests {
4343
private static final TypeReference<Set<String>> STRING_SET = new TypeReference<Set<String>>() {
4444
};
4545

46+
private static final TypeReference<String[]> STRING_ARRAY = new TypeReference<String[]>() {
47+
};
48+
4649
private ObjectMapper objectMapper;
4750

4851
@BeforeEach
@@ -73,4 +76,12 @@ public void readValueWhenLinkedHashSetThenSuccess() throws Exception {
7376
assertThat(this.objectMapper.readValue(json, STRING_SET)).isEqualTo(set);
7477
}
7578

79+
// gh-1666
80+
@Test
81+
public void readValueWhenStringArrayThenSuccess() throws Exception {
82+
String[] array = new String[] { "one", "two" };
83+
String json = this.objectMapper.writeValueAsString(array);
84+
assertThat(this.objectMapper.readValue(json, STRING_ARRAY)).isEqualTo(array);
85+
}
86+
7687
}

0 commit comments

Comments
 (0)