GithubHelp home page GithubHelp logo

fastjson-jaxrs-json-provider's Introduction

fastjson-jaxrs-json-provider

A JAX-RS entity provider for fastjson

Maven Central Drone Build Status

What is JAXRS provider?

Entity payload, if present in an received HTTP message, is passed to JAX-RS container as an input stream. The stream may, for example, contain data represented as a plain text, XML or JSON document. However, in many JAX-RS components that process these inbound data, such as resource methods or client responses, the JAX-RS API user can access the inbound entity as an arbitrary Java object that is created from the content of the input stream based on the representation type information. For example, an entity created from an input stream that contains data represented as a XML document, can be converted to a custom JAXB bean. Similar concept is supported for the outbound entities. An entity returned from the resource method in the form of an arbitrary Java object can be serialized by JAX-RS container into a container output stream as a specified representation. Of course, while JAX-RS implementations do provide default support for most common combinations of Java type and it's respective on-the-wire representation formats, JAX-RS implementations do not support the conversion described above for any arbitrary Java type and any arbitrary representation format by default. Instead, a generic extension concept is exposed in JAX-RS API to allow application-level customizations of this JAX-RS runtime to support for entity conversions. The JAX-RS extension API components that provide the user-level extensibility are typically referred to by several terms with the same meaning, such as entity providers, message body providers, message body workers or message body readers and writers. You may find all these terms used interchangeably throughout the user guide and they all refer to the same concept.

In JAX-RS extension API (or SPI - service provider interface, if you like) the concept is captured in 2 interfaces. One for handling inbound entity representation-to-Java de-serialization - MessageBodyReader and the other one for handling the outbound entity Java-to-representation serialization - MessageBodyWriter. A MessageBodyReader, as the name suggests, is an extension that supports reading the message body representation from an input stream and converting the data into an instance of a specific Java type. A MessageBodyWriter is then responsible for converting a message payload from an instance of a specific Java type into a specific representation format that is sent over the wire to the other party as part of an HTTP message exchange. Both of these providers can be used to provide message payload serialization and de-serialization support on the server as well as the client side. A message body reader or writer is always used whenever a HTTP request or response contains an entity and the entity is either requested by the application code (e.g. injected as a parameter of JAX-RS resource method or a response entity read on the client from a Response) or has to be serialized and sent to the other party (e.g. an instance returned from a JAX-RS resource method or a request entity sent by a JAX-RS client).

please read https://jersey.java.net/documentation/latest/message-body-workers.html to learn how providers work.

Introduction

FastJsonProvider is a standard entity provider that follows JAX-RS 2.0 spec. According to different JAX-RS implementations such as CXF, Jersey, maybe you use FastJsonProvider in appropriate styles. FastJsonProvider can serialize/deserialize specific types including:

  • all types: public FastJsonProvider() (default constructor)
  • all type annotated with FastJsonType: public FastJsonProvider(boolean annotated)
  • all type annotated in specific packages : public FastJsonProvider(String[] scanpackages)
  • all type annotated in specific packages with FastJsonType: public FastJsonProvider(String[] scanpackages, boolean annotated)
  • all type in specific classes: public FastJsonProvider(Class<?>[] clazzes)

You can init this provider instance with a FastJsonConfig object which is used to configure FastJson features, SerializeConfig, ParserConfig and SerializeFilter. Any parameters can be null and will be default.

Maven

stable version: 0.3.2

<dependency>
	<groupId>com.colobu</groupId>
	<artifactId>fastjson-jaxrs-json-provider</artifactId>
	<version>0.3.2</version>
<dependency>

snapshot version: 0.3.3-SNAPSHOT

<dependency>
	<groupId>com.colobu</groupId>
	<artifactId>fastjson-jaxrs-json-provider</artifactId>
	<version>0.3.3-SNAPSHOT</version>
<dependency>

Jersey configuration

Please check the test and maybe you need to create a FastJsonFeature to override MessageBodyReader and MessageBodyWriter.

CXF confguration

You can use JAXRSServerFactoryBean.setProviders to add a FastJsonProvider instance.

fastjson-jaxrs-json-provider's People

Contributors

dependabot[bot] avatar smallnest avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

fastjson-jaxrs-json-provider's Issues

增加pretty format支持?

比如用户在请求参数里有 ?pretty=true ,则输出格式化好的JSON数据。

当然,简单地可以全局地实现配置FastJSON都输出格式化好的,但如果想从请求参数里来判断,需要用Filter来处理?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.