當前位置: 首頁>>代碼示例>>Java>>正文


Java JSONJAXBContext類代碼示例

本文整理匯總了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);
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:22,代碼來源:JAXBContextResolver.java

示例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;
}
 
開發者ID:hopshadoop,項目名稱:hops,代碼行數:22,代碼來源:TestRMWebServicesReservation.java

示例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);
}
 
開發者ID:karma-exchange-org,項目名稱:karma-exchange,代碼行數:27,代碼來源:JsonValidationTestUtil.java

示例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);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:8,代碼來源:JAXBContextResolver.java

示例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();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:9,代碼來源:TestRMWebServicesNodeLabels.java

示例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);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:8,代碼來源:TestRMWebServicesNodeLabels.java

示例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();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:8,代碼來源:TestRMWebServicesAppsModification.java

示例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();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:8,代碼來源:TestRMWebServicesAppsModification.java

示例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();
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:15,代碼來源:ScannerModel.java

示例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();
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:15,代碼來源:ScannerModel.java

示例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();
}
 
開發者ID:aliyun-beta,項目名稱:aliyun-oss-hadoop-fs,代碼行數:9,代碼來源:TestRMWebServicesAppsModification.java

示例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;
}
 
開發者ID:aliyun-beta,項目名稱:aliyun-oss-hadoop-fs,代碼行數:38,代碼來源:TestRMWebServicesReservation.java

示例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());

}
 
開發者ID:aliyun-beta,項目名稱:aliyun-oss-hadoop-fs,代碼行數:37,代碼來源:TestRMWebServicesReservation.java

示例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());

}
 
開發者ID:aliyun-beta,項目名稱:aliyun-oss-hadoop-fs,代碼行數:37,代碼來源:TestRMWebServicesReservation.java

示例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);
    }
}
 
開發者ID:dcos,項目名稱:exhibitor,代碼行數:29,代碼來源:NaturalNotationContextResolver.java


注:本文中的com.sun.jersey.api.json.JSONJAXBContext類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。