
org.glassfish.jersey.media.htmljson.HtmlJsonProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of html-json Show documentation
Show all versions of html-json Show documentation
JAX-RS Reader/Writer via net.java.html.json library that provides
JSON serialization and deserialization using lightweight (no reflection)
net.java.html.json library. Define your objects via @Model annotation.
Use them in Jersey.
The newest version!
/*
* Copyright (c) 2010, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package org.glassfish.jersey.media.htmljson;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Array;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.client.WebTarget;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.ext.MessageBodyReader;
import jakarta.ws.rs.ext.MessageBodyWriter;
import org.openide.util.lookup.ServiceProvider;
import org.openide.util.lookup.ServiceProviders;
import net.java.html.BrwsrCtx;
import net.java.html.json.Model;
import net.java.html.json.Models;
import net.java.html.json.Property;
/**
* Implementation of Jersey's message body reader and writer that
* can handle reading and writing of JSON models generated by {@link Model}
* annotation provided by
* net.java.html.json
* library. Include
* this JAR in your project and you can then use your
* model classes as Jersey's entities.
*
*
* {@link Model @Model}(className="Query", properties={
* {@link Property @Property}(name="items", type=Item.class, array=true)
* })
* class QueryImpl {
*
* {@link Model @Model}(className="Item", properties={
* {@link Property @Property}(name="id", type=String.class),
* {@link Property @Property}(name="kind", type=Kind.class)
* })
* class ItemImpl {
* }
*
* enum Kind {
* GOOD, BAD
* }
*
* public static List{@code - } doQuery() {
* {@link WebTarget} target = ...;
* Query q = target.request(MediaType.APPLICATION_JSON).get().readEntity(Query.class);
* return q.getItems();
* }
* }
*
*
* @author Jaroslav Tulach (jtulach at netbeans.org)
*/
@ServiceProviders({
@ServiceProvider(service = MessageBodyWriter.class),
@ServiceProvider(service = MessageBodyReader.class)
})
public final class HtmlJsonProvider implements MessageBodyWriter
© 2015 - 2025 Weber Informatics LLC | Privacy Policy