Skip to content

Commit

Permalink
fix(json): json is returned as the default for controllers (#842)
Browse files Browse the repository at this point in the history
  • Loading branch information
emjburns committed Jul 2, 2019
1 parent c99ffee commit a7952d7
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ import com.netflix.spinnaker.fiat.shared.FiatService
import com.netflix.spinnaker.fiat.shared.FiatStatus
import com.netflix.spinnaker.filters.AuthenticatedRequestFilter
import com.netflix.spinnaker.gate.config.PostConnectionConfiguringJedisConnectionFactory.ConnectionPostProcessor
import com.netflix.spinnaker.gate.converters.JsonHttpMessageConverter
import com.netflix.spinnaker.gate.converters.YamlHttpMessageConverter
import com.netflix.spinnaker.gate.filters.CorsFilter
import com.netflix.spinnaker.gate.filters.GateOriginValidator
import com.netflix.spinnaker.gate.filters.OriginValidator
import com.netflix.spinnaker.gate.retrofit.EurekaOkClient
import com.netflix.spinnaker.gate.retrofit.Slf4jRetrofitLogger
import com.netflix.spinnaker.gate.services.EurekaLookupService
import com.netflix.spinnaker.gate.services.internal.*
import com.netflix.spinnaker.gate.yaml.YamlHttpMessageConverter
import com.netflix.spinnaker.kork.dynamicconfig.DynamicConfigService
import com.netflix.spinnaker.kork.web.selector.DefaultServiceSelector
import com.netflix.spinnaker.kork.web.selector.SelectableService
Expand All @@ -56,7 +57,6 @@ import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Primary
import org.springframework.core.Ordered
import org.springframework.http.MediaType
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter
import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer
import org.springframework.session.data.redis.config.ConfigureRedisAction
Expand Down Expand Up @@ -141,13 +141,22 @@ class GateConfig extends RedisHttpSessionConfiguration {
@Autowired
ServiceConfiguration serviceConfiguration

/**
* This needs to be before the yaml converter in order for json to be the default
* response type.
*/
@Bean
AbstractJackson2HttpMessageConverter jsonHttpMessageConverter() {
ObjectMapper objectMapper = new ObjectMapper()
.enable(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)

return new JsonHttpMessageConverter(objectMapper)
}

@Bean
AbstractJackson2HttpMessageConverter yamlHttpMessageConverter() {
return new YamlHttpMessageConverter(
new YAMLMapper(),
MediaType.parseMediaType("application/x-yaml"),
MediaType.parseMediaType("application/x-yaml;charset=UTF-8")
)
return new YamlHttpMessageConverter(new YAMLMapper())
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
*
* Copyright 2019 Netflix, Inc.
*
* 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
*
* http://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 com.netflix.spinnaker.gate.converters;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.http.MediaType;
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter;

public class JsonHttpMessageConverter extends AbstractJackson2HttpMessageConverter {
public JsonHttpMessageConverter(ObjectMapper objectMapper) {
super(
objectMapper,
MediaType.parseMediaType("application/json"),
MediaType.parseMediaType("application/json;charset=UTF-8"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@
* limitations under the License.
*
*/
package com.netflix.spinnaker.gate.yaml;
package com.netflix.spinnaker.gate.converters;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.http.MediaType;
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter;

public class YamlHttpMessageConverter extends AbstractJackson2HttpMessageConverter {

public YamlHttpMessageConverter(ObjectMapper objectMapper, MediaType... supportedMediaTypes) {
super(objectMapper, supportedMediaTypes);
public YamlHttpMessageConverter(ObjectMapper objectMapper) {
super(
objectMapper,
MediaType.parseMediaType("application/x-yaml"),
MediaType.parseMediaType("application/x-yaml;charset=UTF-8"));
}
}

0 comments on commit a7952d7

Please sign in to comment.