Search in sources :

Example 21 with MappingJackson2JsonView

use of org.springframework.web.servlet.view.json.MappingJackson2JsonView in project spring-framework by spring-projects.

the class ViewResolverRegistryTests method contentNegotiation.

@Test
public void contentNegotiation() {
    MappingJackson2JsonView view = new MappingJackson2JsonView();
    this.registry.enableContentNegotiation(view);
    ContentNegotiatingViewResolver resolver = checkAndGetResolver(ContentNegotiatingViewResolver.class);
    assertThat(resolver.getDefaultViews()).isEqualTo(Arrays.asList(view));
    assertThat(this.registry.getOrder()).isEqualTo(Ordered.HIGHEST_PRECEDENCE);
}
Also used : ContentNegotiatingViewResolver(org.springframework.web.servlet.view.ContentNegotiatingViewResolver) MappingJackson2JsonView(org.springframework.web.servlet.view.json.MappingJackson2JsonView) Test(org.junit.jupiter.api.Test)

Example 22 with MappingJackson2JsonView

use of org.springframework.web.servlet.view.json.MappingJackson2JsonView in project disconf by knightliao.

the class JsonObjectUtils method JsonObjectError2ModelView.

/**
 */
public static ModelAndView JsonObjectError2ModelView(JsonObjectError json) {
    ModelAndView model = new ModelAndView(new MappingJackson2JsonView());
    model.addObject(FrontEndInterfaceConstant.RETURN_SUCCESS, json.getSuccess());
    model.addObject(FrontEndInterfaceConstant.RETURN_MESSAGE, json.getMessage());
    model.addObject(FrontEndInterfaceConstant.STATUS_CODE_STRING, json.getStatus());
    model.addObject(FrontEndInterfaceConstant.SESSION_ID, json.getSessionId());
    return model;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) MappingJackson2JsonView(org.springframework.web.servlet.view.json.MappingJackson2JsonView)

Aggregations

MappingJackson2JsonView (org.springframework.web.servlet.view.json.MappingJackson2JsonView)22 ModelAndView (org.springframework.web.servlet.ModelAndView)11 ContentNegotiatingViewResolver (org.springframework.web.servlet.view.ContentNegotiatingViewResolver)7 lombok.val (lombok.val)5 Test (org.junit.jupiter.api.Test)5 MarshallingView (org.springframework.web.servlet.view.xml.MarshallingView)5 ArrayList (java.util.ArrayList)4 Jaxb2Marshaller (org.springframework.oxm.jaxb.Jaxb2Marshaller)4 View (org.springframework.web.servlet.View)4 InternalResourceViewResolver (org.springframework.web.servlet.view.InternalResourceViewResolver)4 ValidationError (com.breuninger.arch.playground.common.domain.ValidationError)3 HashMap (java.util.HashMap)3 ContentNegotiationManager (org.springframework.web.accept.ContentNegotiationManager)3 FixedContentNegotiationStrategy (org.springframework.web.accept.FixedContentNegotiationStrategy)3 HeaderContentNegotiationStrategy (org.springframework.web.accept.HeaderContentNegotiationStrategy)3 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)3 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)3 LinkedHashMap (java.util.LinkedHashMap)2 Bean (org.springframework.context.annotation.Bean)2 WebTestClient (org.springframework.test.web.reactive.server.WebTestClient)2