本文整理匯總了Java中com.sun.jersey.api.json.JSONJAXBContext類的典型用法代碼示例。如果您正苦於以下問題:Java JSONJAXBContext類的具體用法?Java JSONJAXBContext怎麽用?Java JSONJAXBContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
JSONJAXBContext類屬於com.sun.jersey.api.json包,在下文中一共展示了JSONJAXBContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: JAXBContextResolver
import com.sun.jersey.api.json.JSONJAXBContext; //導入依賴的package包/類
public JAXBContextResolver() throws Exception {
Class[] typesArr =
new Class[]{ZPath.class, ZStat.class, ZChildrenJSON.class};
typesSet = new HashSet<Class>(Arrays.asList(typesArr));
context = new JSONJAXBContext(
JSONConfiguration.mapped()
.arrays("children")
.nonStrings("czxid")
.nonStrings("mzxid")
.nonStrings("ctime")
.nonStrings("mtime")
.nonStrings("version")
.nonStrings("cversion")
.nonStrings("aversion")
.nonStrings("ephemeralOwner")
.nonStrings("dataLength")
.nonStrings("numChildren")
.nonStrings("pzxid")
.build(),
typesArr);
}
示例2: submitAndVerifyReservation
import com.sun.jersey.api.json.JSONJAXBContext; //導入依賴的package包/類
private ClientResponse submitAndVerifyReservation(String path, String media,
String reservationJson) throws Exception {
JSONJAXBContext jc =
new JSONJAXBContext(JSONConfiguration.mapped()
.build(), ReservationSubmissionRequestInfo.class);
JSONUnmarshaller unmarshaller = jc.createJSONUnmarshaller();
ReservationSubmissionRequestInfo rsci =
unmarshaller.unmarshalFromJSON(new StringReader(reservationJson),
ReservationSubmissionRequestInfo.class);
Thread.sleep(1000);
ClientResponse response =
constructWebResource(path).entity(rsci, MediaType.APPLICATION_JSON)
.accept(media).post(ClientResponse.class);
if (!this.isAuthenticationEnabled()) {
assertEquals(Status.UNAUTHORIZED, response.getClientResponseStatus());
}
return response;
}
示例3: validateJsonConversion
import com.sun.jersey.api.json.JSONJAXBContext; //導入依賴的package包/類
public static <T> void validateJsonConversion(T entity, Class<T> entityClass)
throws JAXBException {
JSONJAXBContext jsonContext = new JSONJAXBContext(
JSONConfiguration.natural().humanReadableFormatting(true).build(),
entityClass);
JSONMarshaller jsonMarshaller = jsonContext.createJSONMarshaller();
StringWriter jsonEntityStringWriter = new StringWriter();
jsonMarshaller.marshallToJSON(entity, jsonEntityStringWriter);
String jsonEntityStr = jsonEntityStringWriter.toString();
if (DEBUG) {
System.out.println("Json:\n" + jsonEntityStr);
}
JSONUnmarshaller jsonUnmarshaller = jsonContext.createJSONUnmarshaller();
T unmarshalledEntity = jsonUnmarshaller.unmarshalFromJSON(
new StringReader(jsonEntityStr),
entityClass);
if (DEBUG) {
System.out.println(entity);
}
assertEquals(entity, unmarshalledEntity);
}
示例4: JAXBContextResolver
import com.sun.jersey.api.json.JSONJAXBContext; //導入依賴的package包/類
public JAXBContextResolver() throws Exception {
this.types = new HashSet<Class>(Arrays.asList(cTypes));
// sets the json configuration so that the json output looks like
// the xml output
this.context = new JSONJAXBContext(JSONConfiguration.natural().
rootUnwrapping(false).build(), cTypes);
}
示例5: toJson
import com.sun.jersey.api.json.JSONJAXBContext; //導入依賴的package包/類
@SuppressWarnings("rawtypes")
private String toJson(Object nsli, Class klass) throws Exception {
StringWriter sw = new StringWriter();
JSONJAXBContext ctx = new JSONJAXBContext(klass);
JSONMarshaller jm = ctx.createJSONMarshaller();
jm.marshallToJSON(nsli, sw);
return sw.toString();
}
示例6: fromJson
import com.sun.jersey.api.json.JSONJAXBContext; //導入依賴的package包/類
@SuppressWarnings({ "rawtypes", "unchecked" })
private Object fromJson(String json, Class klass) throws Exception {
StringReader sr = new StringReader(json);
JSONJAXBContext ctx = new JSONJAXBContext(klass);
JSONUnmarshaller jm = ctx.createJSONUnmarshaller();
return jm.unmarshalFromJSON(sr, klass);
}
示例7: appStateToJSON
import com.sun.jersey.api.json.JSONJAXBContext; //導入依賴的package包/類
private static String appStateToJSON(AppState state) throws Exception {
StringWriter sw = new StringWriter();
JSONJAXBContext ctx = new JSONJAXBContext(AppState.class);
JSONMarshaller jm = ctx.createJSONMarshaller();
jm.marshallToJSON(state, sw);
return sw.toString();
}
示例8: appQueueToJSON
import com.sun.jersey.api.json.JSONJAXBContext; //導入依賴的package包/類
protected static String appQueueToJSON(AppQueue targetQueue) throws Exception {
StringWriter sw = new StringWriter();
JSONJAXBContext ctx = new JSONJAXBContext(AppQueue.class);
JSONMarshaller jm = ctx.createJSONMarshaller();
jm.marshallToJSON(targetQueue, sw);
return sw.toString();
}
示例9: buildFilter
import com.sun.jersey.api.json.JSONJAXBContext; //導入依賴的package包/類
/**
* @param s the JSON representation of the filter
* @return the filter
* @throws Exception
*/
public static Filter buildFilter(String s) throws Exception {
JSONJAXBContext context =
new JSONJAXBContext(JSONConfiguration.natural().build(),
FilterModel.class);
JSONUnmarshaller unmarshaller = context.createJSONUnmarshaller();
FilterModel model = unmarshaller.unmarshalFromJSON(new StringReader(s),
FilterModel.class);
return model.build();
}
示例10: stringifyFilter
import com.sun.jersey.api.json.JSONJAXBContext; //導入依賴的package包/類
/**
* @param filter the filter
* @return the JSON representation of the filter
* @throws Exception
*/
public static String stringifyFilter(final Filter filter) throws Exception {
JSONJAXBContext context =
new JSONJAXBContext(JSONConfiguration.natural().build(),
FilterModel.class);
JSONMarshaller marshaller = context.createJSONMarshaller();
StringWriter writer = new StringWriter();
marshaller.marshallToJSON(new FilterModel(filter), writer);
return writer.toString();
}
示例11: appPriorityToJSON
import com.sun.jersey.api.json.JSONJAXBContext; //導入依賴的package包/類
protected static String appPriorityToJSON(AppPriority targetPriority)
throws Exception {
StringWriter sw = new StringWriter();
JSONJAXBContext ctx = new JSONJAXBContext(AppPriority.class);
JSONMarshaller jm = ctx.createJSONMarshaller();
jm.marshallToJSON(targetPriority, sw);
return sw.toString();
}
示例12: testSubmissionReservationHelper
import com.sun.jersey.api.json.JSONJAXBContext; //導入依賴的package包/類
private ReservationId testSubmissionReservationHelper(String path,
String media) throws JSONException, Exception {
String reservationJson = loadJsonFile("submit-reservation.json");
JSONJAXBContext jc =
new JSONJAXBContext(JSONConfiguration.mapped()
.build(), ReservationSubmissionRequestInfo.class);
JSONUnmarshaller unmarshaller = jc.createJSONUnmarshaller();
ReservationSubmissionRequestInfo rsci =
unmarshaller.unmarshalFromJSON(new StringReader(reservationJson),
ReservationSubmissionRequestInfo.class);
Thread.sleep(1000);
ClientResponse response =
constructWebResource(path).entity(rsci, MediaType.APPLICATION_JSON)
.accept(media).post(ClientResponse.class);
if (!this.isAuthenticationEnabled()) {
assertEquals(Status.UNAUTHORIZED, response.getClientResponseStatus());
return null;
}
System.out.println("RESPONSE:" + response);
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length());
ReservationId rid = null;
try {
rid = ReservationId.parseReservationId(json.getString("reservation-id"));
assertEquals("incorrect return value", rid.getId(), 1);
} catch (JSONException j) {
// failure is possible and is checked outside
}
return rid;
}
示例13: testUpdateReservationHelper
import com.sun.jersey.api.json.JSONJAXBContext; //導入依賴的package包/類
private void testUpdateReservationHelper(String path,
ReservationId reservationId, String media) throws JSONException,
Exception {
String reservationJson = loadJsonFile("update-reservation.json");
JSONJAXBContext jc =
new JSONJAXBContext(JSONConfiguration.mapped()
.build(), ReservationUpdateRequestInfo.class);
JSONUnmarshaller unmarshaller = jc.createJSONUnmarshaller();
ReservationUpdateRequestInfo rsci =
unmarshaller.unmarshalFromJSON(new StringReader(reservationJson),
ReservationUpdateRequestInfo.class);
if (this.isAuthenticationEnabled()) {
// only works when previous submit worked
if(rsci.getReservationId() == null) {
throw new IOException("Incorrectly parsed the reservatinId");
}
rsci.setReservationId(reservationId.toString());
}
Thread.sleep(1000);
ClientResponse response =
constructWebResource(path).entity(rsci, MediaType.APPLICATION_JSON)
.accept(media).post(ClientResponse.class);
if (!this.isAuthenticationEnabled()) {
assertEquals(Status.UNAUTHORIZED, response.getClientResponseStatus());
return;
}
System.out.println("RESPONSE:" + response);
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
assertEquals(Status.OK, response.getClientResponseStatus());
}
示例14: testDeleteReservationHelper
import com.sun.jersey.api.json.JSONJAXBContext; //導入依賴的package包/類
private void testDeleteReservationHelper(String path,
ReservationId reservationId, String media) throws JSONException,
Exception {
String reservationJson = loadJsonFile("delete-reservation.json");
JSONJAXBContext jc =
new JSONJAXBContext(JSONConfiguration.mapped()
.build(), ReservationDeleteRequestInfo.class);
JSONUnmarshaller unmarshaller = jc.createJSONUnmarshaller();
ReservationDeleteRequestInfo rsci =
unmarshaller.unmarshalFromJSON(new StringReader(reservationJson),
ReservationDeleteRequestInfo.class);
if (this.isAuthenticationEnabled()) {
// only works when previous submit worked
if(rsci.getReservationId() == null) {
throw new IOException("Incorrectly parsed the reservatinId");
}
rsci.setReservationId(reservationId.toString());
}
Thread.sleep(1000);
ClientResponse response =
constructWebResource(path).entity(rsci, MediaType.APPLICATION_JSON)
.accept(media).post(ClientResponse.class);
if (!this.isAuthenticationEnabled()) {
assertEquals(Status.UNAUTHORIZED, response.getClientResponseStatus());
return;
}
System.out.println("RESPONSE:" + response);
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
assertEquals(Status.OK, response.getClientResponseStatus());
}
示例15: NaturalNotationContextResolver
import com.sun.jersey.api.json.JSONJAXBContext; //導入依賴的package包/類
NaturalNotationContextResolver()
{
try
{
this.context = new JSONJAXBContext
(
JSONConfiguration.natural().build(),
Index.class,
Result.class,
SearchId.class,
SearchRequest.class,
SearchResult.class,
UITabSpec.class,
NameAndModifiedDate.class,
PathAnalysis.class,
PathAnalysisNode.class,
PathAnalysisRequest.class,
IdList.class,
UsageListingRequest.class,
FieldValue.class,
ServerStatus.class
);
}
catch ( JAXBException e )
{
throw new RuntimeException(e);
}
}