Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3489848
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:26:41+00:00 2026-05-18T11:26:41+00:00

I am developing RESTful API for my application. All getters (that use HTTP GET)

  • 0

I am developing RESTful API for my application. All getters (that use HTTP GET) work fine. I cannot make save method (that uses POST) to work.

I am using HTML form and RESTClient for testing.

Here is my Controller

@Controller
public class EntitiesController {
 @RequestMapping(value="/ci/save/", method = RequestMethod.POST)
 public ModelAndView saveConfigurationItem(@RequestBody ConfigurationItem body) {
  System.out.println("saveConfigurationItem: body=" + body);
  return createModelAndView("ci", Collections.emptyList());
 }
}

This method is expected to be called when client posts ConfigurationItem.
I am using custom serialization format. It is not XML or JSON. It is VCard or VCalendar format. For my first test I used the following VCard:

BEGIN:VCARD
N:Pooh;Winnie
FN:Winnie the Pooh
TEL:tel:+441234567
END:VCARD

I posted it to URL http://localhost:8080/core.solution-1.0/data/ci/save/.
Here is the response I get:

415
The server refused this request because the request entity is in a format not
supported by the requested resource for the requested method ()

(*) ConfigurationItem is an abstract class. CardEntry extends it. I tried both.

I tried to change the method parameter to String. In this case the method is called but the string is empty. The same happens when following one of recommendations I saw in web I changed the parameter type to MultiValueMap and sent request from simple HTML form.

I saw that marshal() is not called at all.

What’s wrong?

Here is what I have. (I put here relevant code only.)

Spring configuration

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
 xmlns:context="http://www.springframework.org/schema/context"
 xmlns:oxm="http://www.springframework.org/schema/oxm"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
    http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd">

 <import resource="classes/spring-config-prod.xml"/>
 <context:component-scan base-package="com.mycompany.solution.service" />


 <bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />

 <bean id="ciCardView" class="com.mycompany.solution.service.VFormatView">
  <constructor-arg>
   <bean class="com.mycompany.solution.service.VFormatMarshaller">
    <property name="packagesToScan" value="com.mycompany.solution.entity"/>
   </bean>
  </constructor-arg>
 </bean>
</beans>

Marshaller

public class VFormatMarshaller implements Marshaller, Unmarshaller {
 @Override
 public void marshal(Object obj, Result result)
   throws IOException/*, XmlMappingException*/ {
  System.out.println("VFormatMarshaller.marshal(" + obj + ")");
  marshalStreamResult(obj, (StreamResult)result);  
 }

 @Override
 public boolean supports(Class<?> paramClass) {
  System.out.println("VFormatMarshaller.supports(" + paramClass + ")");
  boolean supports = new HashSet<String>(Arrays.asList(packagesToScan)).contains(paramClass.getPackage().getName());
  if (supports) {
   return supports;
  }

  return Collection.class.isAssignableFrom(paramClass);
 }

 @Override
 public Object unmarshal(Source source) throws IOException/*, XmlMappingException*/ {
  System.out.println("VFormatMarshaller.unmarshal(" + source + ")");
  return unmarshalStreamSource((StreamSource)source);
 }
//// .............................
}

View (this is written only to override the content type)

public class VFormatView extends MarshallingView {

 public VFormatView() {
  super();
  setContentType("application/vcard");
  System.out.println("VFormatView()");
 }

 public VFormatView(Marshaller marshaller) {
  super(marshaller);
  setContentType("application/vcard");
  System.out.println("VFormatView(" + marshaller + ")");
 }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T11:26:41+00:00Added an answer on May 18, 2026 at 11:26 am

    @RequestBody/@ResponseBody are supported by an hierarchy of HttpMessageConverters, that is completely different from ViewResolvers.

    In you case you need to configure a MarshallingHttpMessageConverter with appropriate marshaller/unmarshaller and content type (or create your own HttpMessageConverter if you don’t need to depend on the existing implementation of marshaller/unmarshaller), and supply a configured instance to AnnotationMethodHandlerAdapter.

    The least intrusive way to configure a custom HttpMessageConveter is to create a BeanPostProcessor as follows:

    public class Configurer implements BeanPostProcessor {
        public void postProcessAfterInitialization(String name, Object bean) {
            if (bean instanceof AnnotationMethodHandlerAdapter) {
                AnnotationMethodHandlerAdapter a = (AnnotationMethodHandlerAdapter) bean;
                HttpMessageConverter[] convs = a.getMessageConverters();
                ... add new converter ...
                a.setMessageConverters(convs);
            }
        }
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.