
org.glassfish.jersey.examples.jettison.JaxbContextResolver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of json-jettison Show documentation
Show all versions of json-jettison Show documentation
Jersey JSON with Jettison JAXB example.
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 Distribution License v. 1.0, which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package org.glassfish.jersey.examples.jettison;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import jakarta.ws.rs.ext.ContextResolver;
import jakarta.ws.rs.ext.Provider;
import jakarta.xml.bind.JAXBContext;
import org.glassfish.jersey.jettison.JettisonConfig;
import org.glassfish.jersey.jettison.JettisonJaxbContext;
/**
* {@link ContextResolver Context resolver} for {@link JAXBContext}.
*
* @author Jakub Podlesak
* @author Marek Potociar
*/
@Provider
public final class JaxbContextResolver implements ContextResolver {
private final JAXBContext context;
private final Set> types;
private final Class>[] cTypes = {Flights.class, FlightType.class, AircraftType.class};
public JaxbContextResolver() throws Exception {
this.types = new HashSet>(Arrays.asList(cTypes));
this.context = new JettisonJaxbContext(JettisonConfig.DEFAULT, cTypes);
}
@Override
public JAXBContext getContext(Class> objectType) {
return (types.contains(objectType)) ? context : null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy