Java 类org.springframework.http.converter.json.MappingJacksonHttpMessageConverter 实例源码

项目:class-guard    文件:WebMvcConfigurationSupport.java   
/**
 * Adds a set of default HttpMessageConverter instances to the given list.
 * Subclasses can call this method from {@link #configureMessageConverters(List)}.
 * @param messageConverters the list to add the default message converters to
 */
protected final void addDefaultHttpMessageConverters(List<HttpMessageConverter<?>> messageConverters) {
    StringHttpMessageConverter stringConverter = new StringHttpMessageConverter();
    stringConverter.setWriteAcceptCharset(false);

    messageConverters.add(new ByteArrayHttpMessageConverter());
    messageConverters.add(stringConverter);
    messageConverters.add(new ResourceHttpMessageConverter());
    messageConverters.add(new SourceHttpMessageConverter<Source>());
    messageConverters.add(new AllEncompassingFormHttpMessageConverter());

    if (romePresent) {
        messageConverters.add(new AtomFeedHttpMessageConverter());
        messageConverters.add(new RssChannelHttpMessageConverter());
    }
    if (jaxb2Present) {
        messageConverters.add(new Jaxb2RootElementHttpMessageConverter());
    }
    if (jackson2Present) {
        messageConverters.add(new MappingJackson2HttpMessageConverter());
    }
    else if (jacksonPresent) {
        messageConverters.add(new MappingJacksonHttpMessageConverter());
    }
}
项目:class-guard    文件:JsonPathRequestMatcherTests.java   
@Before
public void setup() {
    this.people = new LinkedMultiValueMap<String, Person>();
    this.people.add("composers", new Person("Johann Sebastian Bach"));
    this.people.add("composers", new Person("Johannes Brahms"));
    this.people.add("composers", new Person("Edvard Grieg"));
    this.people.add("composers", new Person("Robert Schumann"));
    this.people.add("performers", new Person("Vladimir Ashkenazy"));
    this.people.add("performers", new Person("Yehudi Menuhin"));

    List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
    converters.add(new MappingJacksonHttpMessageConverter());

    this.restTemplate = new RestTemplate();
    this.restTemplate.setMessageConverters(converters);

    this.mockServer = MockRestServiceServer.createServer(this.restTemplate);
}
项目:lodms-plugins    文件:WkdSpotlightTagger.java   
private SpotlightAnnotation getTagsFor(URI fragment,String text) throws TransformException {
    RestTemplate rest = new RestTemplate();
    CommonsClientHttpRequestFactory clientHttpRequestFactory = new CommonsClientHttpRequestFactory();
    clientHttpRequestFactory.setReadTimeout(10000);
    rest.setRequestFactory(clientHttpRequestFactory);
    List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
    converters.add(new MappingJacksonHttpMessageConverter());
    converters.add(new FormHttpMessageConverter());
    rest.setMessageConverters(converters);
    MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
    map.add("prefix", fragment.toString()+"#");
    map.add("text", text.toString());
    HttpEntity<?> httpEntity = new HttpEntity<Object>(map, getHttpHeaders());
    try {
        SpotlightAnnotation annotation = rest.postForObject(config.getSpotlightUrl(), httpEntity, SpotlightAnnotation.class);
        annotation.setFragmentURI(fragment);
        return annotation;
    }
    catch (RestClientException e) {
        log.warn("could not request tags for: " + text);
        log.warn(e.getMessage());
        return new SpotlightAnnotation();
    }
}
项目:ShoppingMall    文件:RestTemplate.java   
public static void init(List<HttpMessageConverter<?>> messageConverters) {
    messageConverters.add(new ByteArrayHttpMessageConverter());
    messageConverters.add(new StringHttpMessageConverter());
    messageConverters.add(new ResourceHttpMessageConverter());

    // if javax.xml.transform is not available, fall back to standard Form message converter
    if (javaxXmlTransformPresent) {
        messageConverters.add(new SourceHttpMessageConverter<Source>());
        messageConverters.add(new XmlAwareFormHttpMessageConverter());
    } else {
        messageConverters.add(new FormHttpMessageConverter());
    }

    if (simpleXmlPresent) {
        messageConverters.add(new SimpleXmlHttpMessageConverter());
    }

    if (jackson2Present) {
        messageConverters.add(new MappingJackson2HttpMessageConverter());
    } else if (jacksonPresent) {
        messageConverters.add(new MappingJacksonHttpMessageConverter());
    }

    if (romePresent) {
        messageConverters.add(new SyndFeedHttpMessageConverter());
    }
}
项目:Novie    文件:ContextConfig.java   
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {

    converters.add(new StringHttpMessageConverter());
    converters.add(new Jaxb2RootElementHttpMessageConverter());
    converters.add(new MappingJacksonHttpMessageConverter());
    converters.add(new ReportCsvMessageConverter());
}
项目:class-guard    文件:ContentRequestMatcherTests.java   
@Before
public void setup() {
    List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
    converters.add(new StringHttpMessageConverter());
    converters.add(new MappingJacksonHttpMessageConverter());

    this.restTemplate = new RestTemplate();
    this.restTemplate.setMessageConverters(converters);

    this.mockServer = MockRestServiceServer.createServer(this.restTemplate);
}
项目:class-guard    文件:HeaderRequestMatcherTests.java   
@Before
public void setup() {
    List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
    converters.add(new StringHttpMessageConverter());
    converters.add(new MappingJacksonHttpMessageConverter());

    this.restTemplate = new RestTemplate();
    this.restTemplate.setMessageConverters(converters);

    this.mockServer = MockRestServiceServer.createServer(this.restTemplate);
}
项目:class-guard    文件:AnnotationDrivenBeanDefinitionParser.java   
private ManagedList<?> getMessageConverters(Element element, Object source, ParserContext parserContext) {
    Element convertersElement = DomUtils.getChildElementByTagName(element, "message-converters");
    ManagedList<? super Object> messageConverters = new ManagedList<Object>();
    if (convertersElement != null) {
        messageConverters.setSource(source);
        for (Element beanElement : DomUtils.getChildElementsByTagName(convertersElement, "bean", "ref")) {
            Object object = parserContext.getDelegate().parsePropertySubElement(beanElement, null);
            messageConverters.add(object);
        }
    }

    if (convertersElement == null || Boolean.valueOf(convertersElement.getAttribute("register-defaults"))) {
        messageConverters.setSource(source);
        messageConverters.add(createConverterDefinition(ByteArrayHttpMessageConverter.class, source));

        RootBeanDefinition stringConverterDef = createConverterDefinition(StringHttpMessageConverter.class, source);
        stringConverterDef.getPropertyValues().add("writeAcceptCharset", false);
        messageConverters.add(stringConverterDef);

        messageConverters.add(createConverterDefinition(ResourceHttpMessageConverter.class, source));
        messageConverters.add(createConverterDefinition(SourceHttpMessageConverter.class, source));
        messageConverters.add(createConverterDefinition(AllEncompassingFormHttpMessageConverter.class, source));

        if (romePresent) {
            messageConverters.add(createConverterDefinition(AtomFeedHttpMessageConverter.class, source));
            messageConverters.add(createConverterDefinition(RssChannelHttpMessageConverter.class, source));
        }
        if (jaxb2Present) {
            messageConverters.add(createConverterDefinition(Jaxb2RootElementHttpMessageConverter.class, source));
        }
        if (jackson2Present) {
            messageConverters.add(createConverterDefinition(MappingJackson2HttpMessageConverter.class, source));
        }
        else if (jacksonPresent) {
            messageConverters.add(createConverterDefinition(MappingJacksonHttpMessageConverter.class, source));
        }
    }
    return messageConverters;
}
项目:class-guard    文件:RequestPartIntegrationTests.java   
@Before
public void setUp() {
    AllEncompassingFormHttpMessageConverter converter = new AllEncompassingFormHttpMessageConverter();
    converter.setPartConverters(Arrays.<HttpMessageConverter<?>>asList(
            new ResourceHttpMessageConverter(), new MappingJacksonHttpMessageConverter()));

    restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory());
    restTemplate.setMessageConverters(Arrays.<HttpMessageConverter<?>>asList(converter));
}
项目:class-guard    文件:RestTemplate.java   
/**
 * Create a new instance of the {@link RestTemplate} using default settings.
 * Default {@link HttpMessageConverter}s are initialized.
 */
public RestTemplate() {
    this.messageConverters.add(new ByteArrayHttpMessageConverter());
    this.messageConverters.add(new StringHttpMessageConverter());
    this.messageConverters.add(new ResourceHttpMessageConverter());
    this.messageConverters.add(new SourceHttpMessageConverter<Source>());
    this.messageConverters.add(new AllEncompassingFormHttpMessageConverter());

    if (romePresent) {
        this.messageConverters.add(new AtomFeedHttpMessageConverter());
        this.messageConverters.add(new RssChannelHttpMessageConverter());
    }
    if (jaxb2Present) {
        this.messageConverters.add(new Jaxb2RootElementHttpMessageConverter());
    }
    if (jackson2Present) {
        this.messageConverters.add(new MappingJackson2HttpMessageConverter());
    }
    else if (jacksonPresent) {
        this.messageConverters.add(new MappingJacksonHttpMessageConverter());
    }
}
项目:class-guard    文件:AllEncompassingFormHttpMessageConverter.java   
public AllEncompassingFormHttpMessageConverter() {
    addPartConverter(new SourceHttpMessageConverter());
    if (jaxb2Present) {
        addPartConverter(new Jaxb2RootElementHttpMessageConverter());
    }
    if (jackson2Present) {
        addPartConverter(new MappingJackson2HttpMessageConverter());
    }
    else if (jacksonPresent) {
        addPartConverter(new MappingJacksonHttpMessageConverter());
    }
}
项目:XPagesExtensionLibrary    文件:RestUtil.java   
private List<HttpMessageConverter<?>> getHttpMessageConverters() {
    List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
    messageConverters.add(new ByteArrayHttpMessageConverter());
    messageConverters.add(new StringHttpMessageConverter());
    messageConverters.add(new ResourceHttpMessageConverter());
    messageConverters.add(new UploadApplicationPayloadHttpMessageConverter());
    messageConverters.add(getFormHttpMessageConverter());
    messageConverters.add(new MappingJacksonHttpMessageConverter());
    return messageConverters;
}
项目:elasticsearch-tmdb-river    文件:APIUtil.java   
public static RestTemplate initTemplate() {
    RestTemplate template = new RestTemplate();
    List<HttpMessageConverter<?>> convertors = template
            .getMessageConverters();
    MappingJacksonHttpMessageConverter converter = new MappingJacksonHttpMessageConverter();
    List<MediaType> mediaTypes = new ArrayList<MediaType>();
    mediaTypes.add(new MediaType("application", "json"));
    converter.setSupportedMediaTypes(mediaTypes);
    convertors.add(converter);
    template.setMessageConverters(convertors);
    return template;
}
项目:dataIngester    文件:APIUtil.java   
public static RestTemplate initTemplate() {
    RestTemplate template = new RestTemplate();
    List<HttpMessageConverter<?>> convertors = template
            .getMessageConverters();
    MappingJacksonHttpMessageConverter converter = new MappingJacksonHttpMessageConverter();
    List<MediaType> mediaTypes = new ArrayList<MediaType>();
    mediaTypes.add(new MediaType("application", "json"));
    converter.setSupportedMediaTypes(mediaTypes);
    convertors.add(converter);
    template.setMessageConverters(convertors);
    return template;
}
项目:fns-projects    文件:LegacyJacksonConfig.java   
@Bean
@ConditionalOnMissingBean
public MappingJacksonHttpMessageConverter mappingJacksonHttpMessageConverter(
        ObjectMapper objectMapper) {
    MappingJacksonHttpMessageConverter converter = new MappingJacksonHttpMessageConverter();
    converter.setObjectMapper(objectMapper);
    return converter;
}
项目:oauth-client-master    文件:WebMvcConfig.java   
@Bean
@Scope(value = "session", proxyMode = ScopedProxyMode.INTERFACES)
public OAuth2RestTemplate facebookRestTemplate() {
    OAuth2RestTemplate template = new OAuth2RestTemplate(facebook(), new DefaultOAuth2ClientContext(
            accessTokenRequest));
    MappingJacksonHttpMessageConverter converter = new MappingJacksonHttpMessageConverter();
    converter.setSupportedMediaTypes(Arrays.asList(MediaType.APPLICATION_JSON,
            MediaType.valueOf("text/javascript")));
    template.setMessageConverters(Arrays.<HttpMessageConverter<?>> asList(converter));
    return template;
}
项目:spring-mvc-base    文件:ListAllPagifiedTest.java   
@Before
public void setUp() {
    request = new MockHttpServletRequest();
    request.setAttribute(HandlerMapping.INTROSPECT_TYPE_LEVEL_MAPPING, true);
    request.setRequestURI("/ajax/listAllPagified");
    request.setMethod("GET");
    response = new MockHttpServletResponse();

    adapter = new AnnotationMethodHandlerAdapter();
    MappingJacksonHttpMessageConverter messageConverter = new MappingJacksonHttpMessageConverter();
    adapter.setMessageConverters(new HttpMessageConverter[] { messageConverter });
    ajaxController = new AjaxController();
    ajaxController.setAccountService(accountService);

}
项目:webmvc    文件:PlaceClient.java   
public static void main(String[] args) {
    trustAllSSL();
    String key = args[0];
    RestTemplate tmpl = new RestTemplate();
    List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
    converters.add(new MappingJacksonHttpMessageConverter());
    tmpl.setMessageConverters(converters);
    PlaceResponse response = tmpl.getForObject(URL, PlaceResponse.class,
            LOCATION, key);
    System.out.println(response);
}
项目:ods-lodms-plugins    文件:RestTemplateFactory.java   
public static RestTemplate getRestTemplate() {
  synchronized (RestTemplateFactory.class) {
    RestTemplate rest = new RestTemplate();
    List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
    converters.add(new MappingJacksonHttpMessageConverter());
    rest.setMessageConverters(converters);
    return rest;
  }
}
项目:ods-lodms-plugins    文件:RestFactory.java   
public static RestTemplate getRest() {
  RestTemplate rest = new RestTemplate();
  List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
  converters.add(new Jaxb2RootElementHttpMessageConverter());
  converters.add(new FormHttpMessageConverter());
  converters.add(new MappingJacksonHttpMessageConverter());
  rest.setMessageConverters(converters);
  return rest;
}
项目:Meetr-Backend    文件:AuthITest.java   
public AuthITest() {
    restTemplate = new RestTemplate();
  List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();

  MappingJacksonHttpMessageConverter jacksonHttpMessageConverter = new MappingJacksonHttpMessageConverter();
  ObjectMapper jacksonMapper = new ObjectMapper();
  jacksonMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  jacksonHttpMessageConverter.setObjectMapper(jacksonMapper);

  messageConverters.add(jacksonHttpMessageConverter);
  messageConverters.addAll(restTemplate.getMessageConverters());

  restTemplate.setMessageConverters(messageConverters);
}
项目:geo-koala-android-client    文件:PublisherServiceUtil.java   
public static JSONObject publish(Collection<Event> events, String username,
    String password, String appKey) throws JsonProcessingException,
    IOException, Exception {

JSONObject statusJSONObject = new JSONObject();

JSONObject topNode = convertToJson(events);

final HttpBasicAuthentication authHeader = new HttpBasicAuthentication(
    username, password);

final HttpHeaders requestHeaders = new HttpHeaders();

requestHeaders.setAuthorization(authHeader);

requestHeaders.add("X-Mashape-Key",
    "E0yCNooETJmsh1J1S4me9PvLaZgXp1Ryh4LjsnsSSjbIYqOxYl");

requestHeaders.add("Content-Type", "application/json");

requestHeaders.setAccept(Collections
    .singletonList(MediaType.APPLICATION_JSON));

HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params,
    HTTP.DEFAULT_CONTENT_CHARSET);
HttpProtocolParams.setUseExpectContinue(params, true);

SchemeRegistry schReg = new SchemeRegistry();
schReg.register(new Scheme("https",
    SSLSocketFactory.getSocketFactory(), 443));

ClientConnectionManager conMgr = new ThreadSafeClientConnManager(
    params, schReg);

HttpClient client = new DefaultHttpClient(conMgr, params);

final HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
factory.setHttpClient(client);

// Create a new RestTemplate instance
final RestTemplate restTemplate = new RestTemplate(factory);

restTemplate.getMessageConverters().add(
    new MappingJacksonHttpMessageConverter());

final String url = "https://twoencore-reaperfire-aka-geokoala-v1.p.mashape.com/rest/v1/public/accounts/"
    + appKey + "/events";
 JsonNode featureCollectionJsonNode = null;
try {
    final ObjectMapper mapper = new ObjectMapper();

    featureCollectionJsonNode = mapper.readTree(topNode
        .toString());

    final HttpEntity<JsonNode> entity = new HttpEntity<JsonNode>(
        featureCollectionJsonNode, requestHeaders);

    trustSelfSignedSSL();

    final ResponseEntity<JsonNode> response = restTemplate.exchange(
        url, HttpMethod.POST, entity, JsonNode.class);

    statusJSONObject.put("response", response);

    synchronized (events) {
    events.clear();
    }
} catch (final HttpClientErrorException ex) {
    StringWriter errors = new StringWriter();
    ex.printStackTrace(new PrintWriter(errors));
    statusJSONObject.put("url", url);
    statusJSONObject.put("error", errors.toString());
}

return statusJSONObject;

   }
项目:twinpush-spring-bean    文件:TwinPushConnectionServiceImpl.java   
public TwinPushConnectionServiceImpl()
{
    this.restTemplate = new RestTemplate();
    restTemplate.getMessageConverters().add(new MappingJacksonHttpMessageConverter());
}
项目:spring-greenhouse-clickstart    文件:WebConfig.java   
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    converters.add(new MappingJacksonHttpMessageConverter());
}