Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ARSnova Backend
Manage
Activity
Members
Labels
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Privacy
Imprint
Contact
Snippets
Groups
Projects
Show more breadcrumbs
Paul-Christian Volkmer
ARSnova Backend
Commits
3d973da4
Commit
3d973da4
authored
7 years ago
by
Daniel Gerhardt
Browse files
Options
Downloads
Plain Diff
Merge branch 'versioned-json-mediatypes' into 'master'
Add multi-version API support via media types See merge request !55
parents
f7dcbabf
0d93fe41
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/de/thm/arsnova/config/AppConfig.java
+37
-7
37 additions, 7 deletions
src/main/java/de/thm/arsnova/config/AppConfig.java
with
37 additions
and
7 deletions
src/main/java/de/thm/arsnova/config/AppConfig.java
+
37
−
7
View file @
3d973da4
...
...
@@ -18,6 +18,7 @@
package
de.thm.arsnova.config
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
com.fasterxml.jackson.databind.SerializationFeature
;
import
de.thm.arsnova.ImageUtils
;
import
de.thm.arsnova.connector.client.ConnectorClient
;
import
de.thm.arsnova.connector.client.ConnectorClientImpl
;
...
...
@@ -86,6 +87,8 @@ import java.util.List;
ignoreResourceNotFound
=
true
)
public
class
AppConfig
extends
WebMvcConfigurerAdapter
{
public
static
final
MediaType
API_V2_MEDIA_TYPE
=
new
MediaType
(
"application"
,
"vnd.de.thm.arsnova.v2+json"
);
public
static
final
MediaType
API_V3_MEDIA_TYPE
=
new
MediaType
(
"application"
,
"vnd.de.thm.arsnova.v3+json"
);
@Autowired
private
Environment
env
;
...
...
@@ -101,11 +104,13 @@ public class AppConfig extends WebMvcConfigurerAdapter {
@Value
(
value
=
"${socketio.ssl.jks-password:}"
)
private
String
socketKeystorePassword
;
@Value
(
value
=
"${security.cors.origins:}"
)
private
String
[]
corsOrigins
;
@Value
(
value
=
"${mail.host}"
)
private
String
mailHost
;
@Value
(
value
=
"${api.indent-response-body:false}"
)
private
boolean
apiIndent
;
@Override
public
void
configureMessageConverters
(
List
<
HttpMessageConverter
<?>>
converters
)
{
converters
.
add
(
stringMessageConverter
());
converters
.
add
(
jsonMessageConverter
());
converters
.
add
(
defaultJsonMessageConverter
());
converters
.
add
(
apiV2JsonMessageConverter
());
//converters.add(new MappingJackson2XmlHttpMessageConverter(builder.createXmlMapper(true).build()));
}
...
...
@@ -114,7 +119,7 @@ public class AppConfig extends WebMvcConfigurerAdapter {
configurer
.
mediaType
(
"json"
,
MediaType
.
APPLICATION_JSON_UTF8
);
configurer
.
mediaType
(
"xml"
,
MediaType
.
APPLICATION_XML
);
configurer
.
mediaType
(
"html"
,
MediaType
.
TEXT_HTML
);
configurer
.
defaultContentType
(
MediaType
.
APPLICATION_JSON_UTF8
);
configurer
.
defaultContentType
(
API_V3_MEDIA_TYPE
);
configurer
.
favorParameter
(
true
);
configurer
.
favorPathExtension
(
false
);
}
...
...
@@ -163,13 +168,38 @@ public class AppConfig extends WebMvcConfigurerAdapter {
}
@Bean
public
MappingJackson2HttpMessageConverter
j
sonMessageConverter
()
{
public
MappingJackson2HttpMessageConverter
defaultJ
sonMessageConverter
()
{
Jackson2ObjectMapperBuilder
builder
=
new
Jackson2ObjectMapperBuilder
();
builder
.
serializationInclusion
(
JsonInclude
.
Include
.
NON_EMPTY
);
builder
.
defaultViewInclusion
(
false
);
builder
.
indentOutput
(
true
).
simpleDateFormat
(
"yyyy-MM-dd'T'HH:mm:ssZ"
);
builder
.
serializationInclusion
(
JsonInclude
.
Include
.
NON_EMPTY
)
.
defaultViewInclusion
(
false
)
.
indentOutput
(
apiIndent
)
.
simpleDateFormat
(
"yyyy-MM-dd'T'HH:mm:ssZ"
);
MappingJackson2HttpMessageConverter
converter
=
new
MappingJackson2HttpMessageConverter
(
builder
.
build
());
List
<
MediaType
>
mediaTypes
=
new
ArrayList
<>();
mediaTypes
.
add
(
API_V3_MEDIA_TYPE
);
mediaTypes
.
add
(
MediaType
.
APPLICATION_JSON_UTF8
);
converter
.
setSupportedMediaTypes
(
mediaTypes
);
return
converter
;
}
@Bean
public
MappingJackson2HttpMessageConverter
apiV2JsonMessageConverter
()
{
Jackson2ObjectMapperBuilder
builder
=
new
Jackson2ObjectMapperBuilder
();
builder
.
serializationInclusion
(
JsonInclude
.
Include
.
NON_EMPTY
)
.
defaultViewInclusion
(
false
)
.
indentOutput
(
apiIndent
)
.
featuresToEnable
(
SerializationFeature
.
WRITE_DATES_AS_TIMESTAMPS
)
.
featuresToEnable
(
SerializationFeature
.
WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS
);
MappingJackson2HttpMessageConverter
converter
=
new
MappingJackson2HttpMessageConverter
(
builder
.
build
());
List
<
MediaType
>
mediaTypes
=
new
ArrayList
<>();
mediaTypes
.
add
(
API_V2_MEDIA_TYPE
);
mediaTypes
.
add
(
MediaType
.
APPLICATION_JSON_UTF8
);
converter
.
setSupportedMediaTypes
(
mediaTypes
);
return
new
MappingJackson2HttpMessageConverter
(
builder
.
build
())
;
return
converter
;
}
@Bean
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment