Boxer


Source link: https://github.com/LarsWerkman/Boxer

Boxer

Annotation based serialization library for Java and Android frameworks, by generating boilerplate code.

  • Define classes as serializable with the @Box annotation.
  • By default all fields will be serialized, except fields with the transient modifier
  • the @Wrap annotation will wrap a List fields into the appropriate Subclass. (Subclass needs to have a no-args constructor)
  • Default non-class serialization possible
@Box public class Example {

private int height;
  private transient int width;
  public double weight;

 @Wrap(Stack.class)
  public List<Example> stack;

//Empty constructor for Injection
  public Example(){

}

//Getters and Setters for private fields 
}

Retrieving a Boxer instance, and serializing and de-serializing your data.

Example using the Bundle class:

public class ExampleActivity extends Activity {

@Override
  public void onSaveInstanceState(Bundle outState) {

super.onSaveInstanceState(outState);

 Boxer boxer = Boxer.from(outState);

boxer.add("Example", new Example());

  
}

@Override
  public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

 Boxer boxer = Boxer.from(savedInstanceState);

boxer.get("Example", Example.class);

  
}
 
}

To register your own Boxer wrapper for a specific class:

//Registering a wrapper class for a specific Target class Boxer.registerWrapper(Wrapper.class, Target.class);
  //Removing a wrapper for a specific wrapper class Boxer.removeWrapper(Wrapper.class);
  //Removing a wrapper for a target class Boxer.removeWrapperForType(Target.class);
  //Clearing all the wrappers Boxer.clearWrappers();

TypeAdapters define how an non-Boxable class should be serialized and deserialized. TypeAdapter will need to be registered with the @Adapter annotation. The type parameter of the TypeAdapter should be the class you want to serialize / deserialize.

@Adapter public class DateTypeAdapter extends TypeAdapter<Date> {

private static final String TIME_KEY = "time_key";

@Override
  public void serialize(Boxer<?> boxer, Date object) {

boxer.addLong(TIME_KEY, object.getTime());

  
}

@Override
  public Date deserialize (Boxer<?> boxer) {

return new Date(boxer.getLong(TIME_KEY));

  
}
 
}

@Serialize and @Deserialize are used to annotate methods that will be called after or before serialization or deserialization inside Boxable classes.

Both annotations take an Execution enum as parameter to specify when they will be executed. Default execution behaviour will be after serialization or deserialization.

The method can have a Boxer parameter or be empty.

@Serialize public void serialization(Boxer<?> boxer){
  //Do something 
}
  @Deserialize(Execution.BEFORE) public void deserialization(Boxer<?> boxer){
  //Do something 
}

Current supported supported classes:

  • (Android) Bundle
  • (Android) Parcel
  • (Android) SQLiteDatabase (Experimental)
  • (Java/Android) DataMap

Beta phase!

Proguard

-dontwarn com.larswerkman.boxer.internal.** -dontwarn com.larswerkman.boxer.wrappers.** -keep class **$$Boxer {
 *; 
}
 -keep class **_TypeAdapter {
 *; 
}
 -keepnames class * {
 @com.larswerkman.boxer.annotations.Box *;
}
 -keepnames class * {
 @com.larswerkman.boxer.annotations.Adapter *;
}
 -keepclasseswithmembernames class * {

  @com.larswerkman.boxer.annotations.* <methods>; 
}

Dependency

Adding it as a dependency to your project.

<dependency>
<groupId>com.larswerkman</groupId>
<artifactId>boxer</artifactId>
<version>0.4.2</version> </dependency>
dependencies {

  compile 'com.larswerkman:boxer:0.4.2' 
}

License

Copyright 2015 Lars Werkman  Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

Developed By

**Lars Werkman**

Resources

Rxjava2 scheduler transformer tools for RxLife.

Use Java Annotations to accelerate your web scraping with Jsoup!

Quickly customize the calendar UI. You can use EasyCalendar to quickly get the calendar style UI.

Feature

  • Custom layout for title.
  • Custom layout for date.
  • Show or hide divider for date.
  • Show or hide overflow date.
  • Listen to date's view be clicked.

Colors is a theming library for Android. It allows your app to use over 4,000 color combinations from the Material Design Palette by separately picking a primary and accent color.

Android utility library which contains usefull utility classes with simple reusable methods.

Fully customized colorfull TabLayout.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes