Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Dec 8, 2020
1 parent 5672166 commit 1195b3a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
Expand All @@ -21,6 +21,7 @@
import org.springframework.aop.Advisor;
import org.springframework.aop.PointcutAdvisor;
import org.springframework.aop.interceptor.ExposeInvocationInterceptor;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;

/**
Expand Down Expand Up @@ -74,7 +75,7 @@ private static boolean isAspectJAdvice(Advisor advisor) {
((PointcutAdvisor) advisor).getPointcut() instanceof AspectJExpressionPointcut));
}

static boolean isVariableName(String name) {
static boolean isVariableName(@Nullable String name) {
if (!StringUtils.hasLength(name)) {
return false;
}
Expand All @@ -88,4 +89,5 @@ static boolean isVariableName(String name) {
}
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ public boolean canRead(Type type, @Nullable Class<?> contextClass, @Nullable Med
}

@Override
public boolean canWrite(@Nullable Type type, @Nullable Class<?> clazz, @Nullable MediaType mediaType) {
public boolean canWrite(@Nullable Type type, Class<?> clazz, @Nullable MediaType mediaType) {
try {
serializer(GenericTypeResolver.resolveType(type, clazz));
serializer(type != null ? GenericTypeResolver.resolveType(type, clazz) : clazz);
return canWrite(mediaType);
}
catch (Exception ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ class KotlinSerializationJsonDecoderTests : AbstractDecoderTests<KotlinSerializa
}
}


@Serializable
data class Pojo(val foo: String, val bar: String)

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ class KotlinSerializationJsonEncoderTests : AbstractEncoderTests<KotlinSerializa
Assertions.assertThat(encoder.canEncode(sseType, MediaType.APPLICATION_JSON)).isFalse()
}


@Serializable
data class Pojo(val foo: String, val bar: String)

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ class KotlinSerializationJsonHttpMessageConverterTests {
assertThat(converter.canWrite(List::class.java, MediaType.APPLICATION_JSON)).isTrue()
assertThat(converter.canWrite(Set::class.java, MediaType.APPLICATION_JSON)).isTrue()

assertThat(converter.canWrite(typeTokenOf<List<Int>>(), null, MediaType.APPLICATION_JSON)).isTrue()
assertThat(converter.canWrite(typeTokenOf<List<SerializableBean>>(), null, MediaType.APPLICATION_JSON)).isTrue()
assertThat(converter.canWrite(typeTokenOf<ArrayList<Int>>(), null, MediaType.APPLICATION_JSON)).isTrue()
assertThat(converter.canWrite(typeTokenOf<List<Int>>(), null, MediaType.APPLICATION_PDF)).isFalse()
assertThat(converter.canWrite(typeTokenOf<List<Int>>(), List::class.java, MediaType.APPLICATION_JSON)).isTrue()
assertThat(converter.canWrite(typeTokenOf<List<SerializableBean>>(), List::class.java, MediaType.APPLICATION_JSON)).isTrue()
assertThat(converter.canWrite(typeTokenOf<ArrayList<Int>>(), List::class.java, MediaType.APPLICATION_JSON)).isTrue()
assertThat(converter.canWrite(typeTokenOf<List<Int>>(), List::class.java, MediaType.APPLICATION_PDF)).isFalse()
}

@Test
Expand Down Expand Up @@ -297,6 +297,7 @@ class KotlinSerializationJsonHttpMessageConverterTests {
assertThat(result).isEqualTo("\"H\u00e9llo W\u00f6rld\"")
}


@Serializable
@Suppress("ArrayInDataClass")
data class SerializableBean(
Expand All @@ -317,4 +318,5 @@ class KotlinSerializationJsonHttpMessageConverterTests {
val superType = base::class.java.genericSuperclass!!
return (superType as ParameterizedType).actualTypeArguments.first()!!
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;

Expand All @@ -31,6 +31,7 @@
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.server.HandshakeInterceptor;
Expand Down Expand Up @@ -84,9 +85,9 @@ public void setAllowedOrigins(Collection<String> allowedOrigins) {
* @since 4.1.5
*/
public Collection<String> getAllowedOrigins() {
return (this.corsConfiguration.getAllowedOrigins() != null ?
Collections.unmodifiableSet(new HashSet<>(this.corsConfiguration.getAllowedOrigins())) :
Collections.emptyList());
List<String> allowedOrigins = this.corsConfiguration.getAllowedOrigins();
return (CollectionUtils.isEmpty(allowedOrigins) ? Collections.emptySet() :
Collections.unmodifiableSet(new LinkedHashSet<>(allowedOrigins)));
}

/**
Expand All @@ -104,14 +105,13 @@ public void setAllowedOriginPatterns(Collection<String> allowedOriginPatterns) {

/**
* Return the allowed {@code Origin} pattern header values.
*
* @since 5.3.2
* @see CorsConfiguration#getAllowedOriginPatterns()
*/
public Collection<String> getAllowedOriginPatterns() {
return (this.corsConfiguration.getAllowedOriginPatterns() != null ?
Collections.unmodifiableSet(new HashSet<>(this.corsConfiguration.getAllowedOriginPatterns())) :
Collections.emptyList());
List<String> allowedOriginPatterns = this.corsConfiguration.getAllowedOriginPatterns();
return (CollectionUtils.isEmpty(allowedOriginPatterns) ? Collections.emptySet() :
Collections.unmodifiableSet(new LinkedHashSet<>(allowedOriginPatterns)));
}


Expand Down

0 comments on commit 1195b3a

Please sign in to comment.