I am creating a simple web service using Spring 3 with Hibernate 5.
My maven dependencies for those are:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.2.14.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>3.2.14.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.2.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.0.1.Final</version>
</dependency>
This isn't my full dependency list but it gives a good idea of the versions I'm using.
The basic requirements of this web service are to provide an endpoint by which a user can request some data based on a unique ID. The data has to be returned as JSON. The data is being retrieved from a SQL Server 2008 database view.
I have successfully configured the web service to use Hibernate and JPA to get the correct data where an ID is matched on a row in the view. The ID is provided as a parameter with the URL, for example:
http://some/resource/location.json?id=1234
Now as I said, this works fine, gets the data if the ID is matched and returns a POJO marshalled as json to the user.
My issue is the requirement to include the '.json' file extension as part of the URL. Ideally I would like the URL to look something like this instead:
http://some/resource/location?id=1234
Notice no '.json'
The view resolver I am using is configured as follows, just ignore the xml stuff, I have that in there because I will need it further down the line:
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="order" value="1"/>
<property name="contentNegotiationManager">
<bean class="org.springframework.web.accept.ContentNegotiationManager">
<constructor-arg>
<bean class="org.springframework.web.accept.PathExtensionContentNegotiationStrategy">
<constructor-arg>
<map>
<entry key="json" value="application/json"/>
<entry key="xml" value="application/xml"/>
</map>
</constructor-arg>
</bean>
</constructor-arg>
</bean>
</property>
<property name="defaultViews">
<list>
<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"/>
<bean class="org.springframework.web.servlet.view.xml.MarshallingView">
<constructor-arg>
<bean class="org.springframework.oxm.xstream.XStreamMarshaller">
<property name="autodetectAnnotations" value="true"/>
</bean>
</constructor-arg>
</bean>
</list>
</property>
</bean>
Is there a different view resolver I should implement maybe?
I can include more detail if needed, just ask, thanks for any help on this.