org.simpleframework.xml.convert.AnnotationStrategy Java Examples

The following examples show how to use org.simpleframework.xml.convert.AnnotationStrategy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AlarmValueImpl.java    From c2mon with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static AlarmValueImpl fromXml(final String xml) throws Exception {

    AlarmValueImpl alarmVal = null;
    StringReader sr = null;
    Serializer serializer = new Persister(new AnnotationStrategy());

    try {
      sr = new StringReader(xml);
      alarmVal = serializer.read(AlarmValueImpl.class, new StringReader(xml), false);
    } finally {

      if (sr != null) {
        sr.close();
      }
    }

    return alarmVal;
  }
 
Example #2
Source File: ConverterMapTest.java    From simplexml with Apache License 2.0 6 votes vote down vote up
public void testMap() throws Exception {
   Strategy strategy = new AnnotationStrategy();
   Serializer serializer = new Persister(strategy);
   MapHolder holder = new MapHolder();
   
   holder.put("a", "A");
   holder.put("b", "B");
   holder.put("c", "C");
   holder.put("d", "D");
   holder.put("e", "E");
   holder.put("f", "F");
   
   serializer.write(holder, System.out);
   
   validate(holder, serializer);
}
 
Example #3
Source File: ConverterDecorationTest.java    From simplexml with Apache License 2.0 6 votes vote down vote up
public void testConverter() throws Exception {
   Style style = new CamelCaseStyle();
   Format format = new Format(style);
   Strategy cycle = new CycleStrategy();
   Strategy strategy = new AnnotationStrategy(cycle);
   Persister persister = new Persister(strategy, format);
   List<ConverterDecorationExample> list = new ArrayList<ConverterDecorationExample>();
   List<NormalExample> normal = new ArrayList<NormalExample>();
   ConverterDecoration example = new ConverterDecoration(list, normal);
   ConverterDecorationExample duplicate = new ConverterDecorationExample("duplicate");
   NormalExample normalDuplicate = new NormalExample("duplicate");
   list.add(duplicate);
   list.add(new ConverterDecorationExample("a"));
   list.add(new ConverterDecorationExample("b"));
   list.add(new ConverterDecorationExample("c"));
   list.add(duplicate);
   list.add(new ConverterDecorationExample("d"));
   list.add(duplicate);
   normal.add(normalDuplicate);
   normal.add(new NormalExample("1"));
   normal.add(new NormalExample("2"));
   normal.add(normalDuplicate);
   persister.write(example, System.err);     
}
 
Example #4
Source File: PathWithConverterTest.java    From simplexml with Apache License 2.0 6 votes vote down vote up
public void testConverterWithPathInHyphenStyle() throws Exception {
   Style style = new HyphenStyle();
   Format format = new Format(style);
   Strategy strategy = new AnnotationStrategy();
   Persister persister = new Persister(strategy, format);
   ServerDetails primary = new ServerDetails("host1.blah.com", 4567, "PRIMARY");
   ServerDetails secondary = new ServerDetails("host2.foo.com", 4567, "SECONDARY");
   ServerDetailsReference reference = new ServerDetailsReference(primary, secondary);
   StringWriter writer = new StringWriter();
   persister.write(reference, writer);
   System.out.println(writer);
   ServerDetailsReference recovered = persister.read(ServerDetailsReference.class, writer.toString());
   assertEquals(recovered.getPrimary().getHost(), reference.getPrimary().getHost());
   assertEquals(recovered.getPrimary().getPort(), reference.getPrimary().getPort());
   assertEquals(recovered.getPrimary().getName(), reference.getPrimary().getName());
   assertEquals(recovered.getSecondary().getHost(), reference.getSecondary().getHost());
   assertEquals(recovered.getSecondary().getPort(), reference.getSecondary().getPort());
   assertEquals(recovered.getSecondary().getName(), reference.getSecondary().getName());
}
 
Example #5
Source File: PathWithConverterTest.java    From simplexml with Apache License 2.0 6 votes vote down vote up
public void testConverterWithPathInCamelStyle() throws Exception {
   Style style = new CamelCaseStyle();
   Format format = new Format(style);
   Strategy strategy = new AnnotationStrategy();
   Persister persister = new Persister(strategy, format);
   ServerDetails primary = new ServerDetails("host1.blah.com", 4567, "PRIMARY");
   ServerDetails secondary = new ServerDetails("host2.foo.com", 4567, "SECONDARY");
   ServerDetailsReference reference = new ServerDetailsReference(primary, secondary);
   StringWriter writer = new StringWriter();
   persister.write(reference, writer);
   System.out.println(writer);
   ServerDetailsReference recovered = persister.read(ServerDetailsReference.class, writer.toString());
   assertEquals(recovered.getPrimary().getHost(), reference.getPrimary().getHost());
   assertEquals(recovered.getPrimary().getPort(), reference.getPrimary().getPort());
   assertEquals(recovered.getPrimary().getName(), reference.getPrimary().getName());
   assertEquals(recovered.getSecondary().getHost(), reference.getSecondary().getHost());
   assertEquals(recovered.getSecondary().getPort(), reference.getSecondary().getPort());
   assertEquals(recovered.getSecondary().getName(), reference.getSecondary().getName());
}
 
Example #6
Source File: ConfigurationLoaderImpl.java    From c2mon with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Retrieve a {@link Serializer} instance suitable for deserialising a
 * {@link ConfigurationReport}.
 *
 * @return a new {@link Serializer} instance
 */
private Serializer getSerializer() {
  DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
  RegistryMatcher matcher = new RegistryMatcher();
  matcher.bind(Timestamp.class, new DateFormatConverter(format));
  Strategy strategy = new AnnotationStrategy();
  Serializer serializer = new Persister(strategy, matcher);
  return serializer;
}
 
Example #7
Source File: ApplicationModule.java    From RetrofitSoapSample with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
public UsStatesApi providesApi(){

    HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();

    interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

    Strategy strategy = new AnnotationStrategy();

    Serializer serializer = new Persister(strategy);

    OkHttpClient okHttpClient = new OkHttpClient.Builder()
            .addInterceptor(interceptor)
            .connectTimeout(2, TimeUnit.MINUTES)
            .writeTimeout(2, TimeUnit.MINUTES)
            .readTimeout(2, TimeUnit.MINUTES)
            .build();

    Retrofit retrofit =  new Retrofit.Builder()
            .addConverterFactory(SimpleXmlConverterFactory.create(serializer))
            .baseUrl("http://www.webservicex.net/")
            .client(okHttpClient)
            .build();

    return retrofit.create( UsStatesApi.class);

}
 
Example #8
Source File: SimpleDatabase.java    From KeePassJava2 with Apache License 2.0 5 votes vote down vote up
/**
 * Utility to get a simple framework persister
 * @return a persister
 * @throws Exception when things get tough
 */
private static Serializer getSerializer() throws Exception {
    Registry registry = new Registry();
    registry.bind(String.class, EmptyStringConverter.class);
    Strategy strategy = new AnnotationStrategy(new RegistryStrategy(registry));
    return new Persister(strategy);

}
 
Example #9
Source File: TalkClient.java    From talk-android with MIT License 4 votes vote down vote up
private TalkClient() {
    restAdapter = new RestAdapter.Builder()
            .setEndpoint(ApiConfig.BASE_URL)
            .setClient(new OkClient())
            .setRequestInterceptor(requestInterceptor)
            .setConverter(new GsonConverter(gson))
            .setErrorHandler(authFailedErrorHandler)
            .setLogLevel(REST_LOG_LEVEL)
            .build();

    uploadAdapter = new RestAdapter.Builder()
            .setEndpoint(ApiConfig.UPLOAD_URL)
            .setClient(new OkClient())
            .setRequestInterceptor(strikerInterceptor)
            .setLogLevel(REST_LOG_LEVEL)
            .build();

    accountAdapter = new RestAdapter.Builder()
            .setEndpoint(ApiConfig.ACCOUNT_URL)
            .setClient(new OkClient())
            .setRequestInterceptor(requestInterceptor)
            .setLogLevel(REST_LOG_LEVEL)
            .build();

    callAdapter = new RestAdapter.Builder()
            .setClient(new OkClient())
            .setEndpoint(ApiConfig.CALL_URL)
            .setConverter(new SimpleXMLConverter(new Persister(new AnnotationStrategy())))
            .setRequestInterceptor(callInterceptor)
            .setLogLevel(REST_LOG_LEVEL)
            .build();

    spiderAdapter = new RestAdapter.Builder()
            .setEndpoint(ApiConfig.SPIDER_URL)
            .setClient(new OkClient())
            .setRequestInterceptor(requestInterceptor)
            .setConverter(new GsonConverter(gson))
            .build();

    tpsAdapter = new RestAdapter.Builder()
            .setClient(new OkClient())
            .setEndpoint(ApiConfig.TPS_API)
            .setRequestInterceptor(requestInterceptor)
            .setLogLevel(REST_LOG_LEVEL)
            .build();

    tbAuthAdapter = new RestAdapter.Builder()
            .setEndpoint(ApiConfig.AUTH_SERVICE_URL)
            .setClient(new OkClient())
            .setRequestInterceptor(requestInterceptor)
            .setConverter(new GsonConverter(gson))
            .setLogLevel(REST_LOG_LEVEL)
            .build();

    deviceId = DeviceUtil.getDeviceId(MainApp.CONTEXT);
}