Fast JSON parser for java projects

Related tags

JSON ig-json-parser
Overview

ig-json-parser

Build Status Release

Fast JSON parser for java projects.

Getting started

The easiest way to get started is to look at maven-example. For more comprehensive examples, check out the unit tests or the demo.

Gradle

For Java projects, to use this library, add this to your build.gradle file:

allprojects {
  repositories {
    maven { url 'https://jitpack.io' }
  }
}

...

dependencies {
  implementation 'com.github.instagram.ig-json-parser:runtime:master-SNAPSHOT' // the runtime
  implementation 'com.github.instagram.ig-json-parser:processor:master-SNAPSHOT' // the annotation processor
}

For Android projects using Android Studio 3.0+ or Gradle 4.0+, you can enable the annotation processor as following:

allprojects {
  repositories {
    maven { url 'https://jitpack.io' }
  }
}

...

dependencies {
  annotationProcessor 'com.github.instagram.ig-json-parser:processor:master-SNAPSHOT'
  implementation 'com.github.instagram.ig-json-parser:runtime:master-SNAPSHOT'
}

If you are using older gradle versions, you can use old apt plugin to integrate the annotation processor:

allprojects {
  repositories {
    maven { url 'https://jitpack.io' }
  }
}

...

apply plugin: 'com.neenbedankt.android-apt'

dependencies {
  apt 'com.github.instagram.ig-json-parser:processor:master-SNAPSHOT'
  implementation 'com.github.instagram.ig-json-parser:runtime:master-SNAPSHOT'
}

If you are using other build systems, please find instructions here

Requirements for model classes

There should be a package-visible no-argument constructor for each of your model classes. The fields also need to be package-visible.

Each class that needs a serializer/deserializer generated should be annotated with @JsonType. Each field that needs to be mapped to/from JSON should be annotated with @JsonField. The @JsonField annotation has one mandatory argument, which is the fieldname for the field in the JSON.

The following is an example of a very simple model class:

@JsonType
class Dessert {
  @JsonField(fieldName="type")
  String type;

  @JsonField(fieldName="rating")
  float rating;
}

Serializer/deserializer

Compiling your model classes with the annotations will automatically generate the serializer and deserializer. They will be in a generated class with the same name as your class, except with the suffix __JsonHelper. For example, to deserialize the Dessert class above, simply run the code:

Dessert parsed = Dessert__JsonHelper.parseFromJson(inputJsonString);

To serialize a class, run:

String serialized = Dessert__JsonHelper.serializeToJson(dessertObject);

Supported data types

The following scalar types are supported:

  • String
  • boolean/Boolean
  • int/Integer
  • long/Long
  • float/Float
  • double/Double

The following collection types are supported:

  • List/ArrayList
  • Queue/ArrayDeque
  • Map/HashMap
  • Set/HashSet

If a json field is another dictionary, it can be represented by another model class. That model class must also have the @JsonType annotation.

Proguard

Add the following lines to your proguard-rules file:

-dontwarn sun.misc.Unsafe
-dontwarn javax.annotation.**

Advanced features

Postprocessing

If you need to process your JSON after a first pass, you can change your @JsonType annotation to be @JsonType(postprocess = true) and add a method to your code and add a method YourClass postprocess() which will be called after the JSON is processed (see: QuestionableDesignChoice in the example below)

  @JsonType
  public class Example {
    @JsonField(fieldName = "container")
    Container mContainer;

    @JsonType
    public static class Container {
        @JsonField(fieldName = "questionable_design_choice")
        List<QuestionableDesignChoice> mQuestionableDesignChoice;
    }

    @JsonType(postprocessingEnabled = true)
    public static class QuestionableDesignChoice {
        @JsonField(fieldName = "property")
        String mProperty;

        QuestionableDesignChoice postprocess() {
          // post-process things here...
          return this;
        }
    }
}

Customized parsing code

Parsing the supported data types is straightforward. For enums or built-in Java classes, you will need to add customized parsing.

Value extract formatters override how we extract the value from the JsonParser object, while serialize code formatters override how we serialize a java field back to json. We use the serde for PointF in the example below, where a point is represented as an array in json.

  @JsonField(
      fieldName = "position",
      valueExtractFormatter =
          "com.instagram.common.json.android.JsonTypeHelper.deserializePointF(${parser_object})",
      serializeCodeFormatter =
          "com.instagram.common.json.android.JsonTypeHelper.serializePointF("
              + "${generator_object}, \"${json_fieldname}\", ${object_varname}.${field_varname})")
  @Nullable
  protected PointF mPosition;

Optional serializer generation

To save generating serializer code if you only need deserialization, serializer generation can be disabled or enabled globally and per-class. The default is to generate serializers for all classes. To disable generation globally, pass

-AgenerateSerializer=false

to the command-line arguments of javac. To override the default generation option for a single class, see JsonType.generateSerializer().

Contributing

See the CONTRIBUTING file for how to help out.

License

ig-json-parser is MIT licensed, as found in the LICENSE file.

Privacy Policy and Terms of Use

Comments
  • Proper documentation + Wiki

    Proper documentation + Wiki

    After going through the demo and unit test projects it took me almost 3 hours to realize how to make this to work. The current documentation only talks about annotating classes and misses consumption and generation of JSON. Proper documentation + Wiki is a must.

    opened by mradzinski 15
  • The Guava Dependency adds 15k methods, can you reduce this?

    The Guava Dependency adds 15k methods, can you reduce this?

    Currently this parser has a dependency on Google's guava library that adds 15082 methods to any project that uses it. Given that the limit for a dex file is only 65k, is there any way you guys can reduce this? If not, can you at least give better proguard documentation? The current documentation for proguard does not seem to work, and neither does the proguard config file in the demo application.

    opened by aneemtalukder 14
  • Add support for serializing/deserializing interfaces

    Add support for serializing/deserializing interfaces

    This PR adds support for serializing objects from an interface reference. Using this, you can serialize out e.g. a list of heterogenous object types.

    Using the Public API

    Say you have a field that refers to an instance of MyInterface.

    @JsonType
    public class MySerializableObject {
      @JsonField(fieldName = "my_interface")
      MyInterface mMyInterface;
    }
    

    First step is to add a method to the interface to return the type name:

    @JsonType
    public interface MyInterface {
      @JsonTypeName
      String getTypeName();
    }
    

    Then in your implementation of that interface, you yield the type name:

    @JsonType
    public class MyImplementation implements MyInterface {
      public static final String TYPE_NAME = "MyImplementation";
      @Override
      public String getTypeName() {
        return TYPE_NAME;
      }
    }
    

    Then before you serialize, you register a serialization handler with the generated code:

    MyInterface__JsonHelper.registerHandler(
      MyImplementation.TYPE_NAME,
      new JsonSerializationHandler<MyInterface>() {
        @Override
        public void serializeToJson(JsonGenerator generator, MyInterface object)
                          throws IOException {
          MyImplementation__JsonHelper
              .serializeToJson(generator, (MyImplementation)object, true);
        }
        public MyInterface parseFromJson(JsonParser parser) throws IOException {
          return MyImplementation__JsonHelper.parseFromJson(parser);
        }
      });
    

    With that, MySerializableObject can successfully serialize and deserialize:

    String json = MySerializableObject__JsonHelper.serializeToJson(object);
    MySerializableObject deserialized = MySerializableObject__JsonHelper.parseFromJson(json);
    

    Under the Hood

    Not seen above is the JSON representation. For this to work, the type has to be represented in the serialized JSON. Not only that, but some ordering must be guaranteed if we want to go with the existing single-pass parse style. This is because we must read in the type first before we dispatch to that specific type's parser.

    The only JSON aggregate that guarantees ordering is the list. So interfaces are represented as lists, where the first entry is the type information, and the second entry is the object data:

    [
      "InterfaceImplementationUUT",
      {
        "stringField":"testValue"
      }
    ]
    
    opened by jingibus 9
  • annotation null pointer exception when List is used as @JsonField in Eclipse

    annotation null pointer exception when List is used as @JsonField in Eclipse

    The exception from the Eclipse .log file is as follows:

    !ENTRY org.eclipse.jdt.apt.pluggable.core 1 1 2015-01-27 00:48:04.922 !MESSAGE annotation exception: java.lang.NullPointerException cause: java.lang.NullPointerException at java.util.regex.Matcher.getTextLength(Matcher.java:1234) at java.util.regex.Matcher.reset(Matcher.java:308) at java.util.regex.Matcher.(Matcher.java:228) at java.util.regex.Pattern.matcher(Pattern.java:1088) at java.util.Formatter.parse(Formatter.java:2515) at java.util.Formatter.format(Formatter.java:2469) at java.util.Formatter.format(Formatter.java:2423) at java.lang.String.format(String.java:2790) at com.instagram.javawriter.JavaWriter.emitStatement(JavaWriter.java:663) at com.instagram.common.json.annotation.processor.JsonParserClassData.writeSerializeCalls(JsonParserClassData.java:514) at com.instagram.common.json.annotation.processor.JsonParserClassData.access$200(JsonParserClassData.java:39) at com.instagram.common.json.annotation.processor.JsonParserClassData$2.emitJava(JsonParserClassData.java:199) at com.instagram.javawriter.JavaWriter.emitWithGenerator(JavaWriter.java:72) at com.instagram.common.json.annotation.processor.JsonParserClassData.getJavaCode(JsonParserClassData.java:183) at com.instagram.common.json.annotation.processor.JsonAnnotationProcessor.process(JsonAnnotationProcessor.java:101) at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.handleProcessor(RoundDispatcher.java:139) at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.round(RoundDispatcher.java:121) at org.eclipse.jdt.internal.compiler.apt.dispatch.BaseAnnotationProcessorManager.processAnnotations(BaseAnnotationProcessorManager.java:159) at org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeAnnotationProcessorManager.processAnnotations(IdeAnnotationProcessorManager.java:134) at org.eclipse.jdt.internal.compiler.Compiler.processAnnotations(Compiler.java:820) at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:434) at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:366) at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.compile(IncrementalImageBuilder.java:329) at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:303) at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.build(IncrementalImageBuilder.java:134) at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildDeltas(JavaBuilder.java:265) at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:193) at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:733) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42) at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:206) at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:246) at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:299) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42) at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:302) at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:358) at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:381) at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143) at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)

    opened by zhaojiac 8
  • IOException on build with Proguard enabled

    IOException on build with Proguard enabled

    Might be a little early to talk about Proguard support, but I'm striking out trying to get it working. This error is from a barebones Android Studio project. Anyone else have any luck?

    Edit: Only trying to shrink for now - no obfuscation.

    org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:proguardDebug'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
        at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:289)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:23)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:86)
        at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
        at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
        at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
        at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54)
        at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:166)
        at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113)
        at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:64)
        at org.gradle.tooling.internal.provider.BuildModelAction.run(BuildModelAction.java:76)
        at org.gradle.tooling.internal.provider.BuildModelAction.run(BuildModelAction.java:31)
        at org.gradle.tooling.internal.provider.ConfiguringBuildAction.run(ConfiguringBuildAction.java:150)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:35)
        at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:45)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
        at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
        at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:42)
        at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
        at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:24)
        at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
        at org.gradle.launcher.daemon.server.exec.StartStopIfBuildAndStop.execute(StartStopIfBuildAndStop.java:33)
        at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
        at org.gradle.launcher.daemon.server.exec.ReturnResult.execute(ReturnResult.java:34)
        at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:71)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:69)
        at org.gradle.util.Swapper.swap(Swapper.java:38)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:69)
        at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
        at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
        at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
        at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:60)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
        at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
        at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:45)
        at org.gradle.launcher.daemon.server.DaemonStateCoordinator.runCommand(DaemonStateCoordinator.java:186)
        at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy.doBuild(StartBuildOrRespondWithBusy.java:49)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
        at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
        at org.gradle.launcher.daemon.server.exec.HandleStop.execute(HandleStop.java:36)
        at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
        at org.gradle.launcher.daemon.server.exec.DaemonHygieneAction.execute(DaemonHygieneAction.java:39)
        at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
        at org.gradle.launcher.daemon.server.exec.CatchAndForwardDaemonFailure.execute(CatchAndForwardDaemonFailure.java:32)
        at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
        at org.gradle.launcher.daemon.server.exec.DefaultDaemonCommandExecuter.executeCommand(DefaultDaemonCommandExecuter.java:51)
        at org.gradle.launcher.daemon.server.DefaultIncomingConnectionHandler$ConnectionWorker.handleCommand(DefaultIncomingConnectionHandler.java:155)
        at org.gradle.launcher.daemon.server.DefaultIncomingConnectionHandler$ConnectionWorker.receiveAndHandleCommand(DefaultIncomingConnectionHandler.java:128)
        at org.gradle.launcher.daemon.server.DefaultIncomingConnectionHandler$ConnectionWorker.run(DefaultIncomingConnectionHandler.java:116)
        at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
        at java.lang.Thread.run(Thread.java:695)
    Caused by: org.gradle.internal.UncheckedException: java.io.IOException: Please correct the above warnings first.
        at org.gradle.internal.UncheckedException.throwAsUncheckedException(UncheckedException.java:39)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:66)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:219)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:212)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:201)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:533)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:516)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
        ... 70 more
    Caused by: java.io.IOException: Please correct the above warnings first.
        at proguard.Initializer.execute(Initializer.java:369)
        at proguard.ProGuard.initialize(ProGuard.java:211)
        at proguard.ProGuard.execute(ProGuard.java:86)
        at proguard.gradle.ProGuardTask.proguard(ProGuardTask.java:1074)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:63)
        ... 77 more
    

    Haven't been able to get the full strack trace, even w/ --full-stacktrace command..

    help wanted 
    opened by TommyVisic 8
  • Add annotation imports

    Add annotation imports

    Another small feature addition while i'm ramped up on this codebase.

    This adds two parameters to @JsonType: imports, and calleeImports.

    imports is straightforward: anything in imports goes into the imports section in generated code. This helps clean up custom code specified in @JsonField:

    @JsonType(imports = "java.util.Formatter")
    public class ImportsUUT {
    
        @JsonField(fieldName = "string_field",
                valueExtractFormatter =
                    "new Formatter().format(\":%%s\", ${parser_object}.getText()).toString()")
        public String mStringField;
    }
    

    calleeImports is the same thing, but for custom code specified on @JsonType. The usage is clearer than the mechanism, so here's a usage example:

    @JsonType(
        valueExtractFormatter = "CalleeImportsCompanionUUT__JsonHelper.parseFromJson(${parser_object})",
        calleeImports = {
            "com.instagram.common.json.annotation.processor.parent.CalleeImportsCompanionUUT__JsonHelper"
        })
    public class CalleeImportsUUT {
      @JsonField(fieldName = "string_field")
      public String mString;
    }
    

    These imports are needed whenever the valueExtractFormatter is used, so they are added in generated classes that refer to this class.

    opened by jingibus 7
  • Switch the demo project to use android-apt

    Switch the demo project to use android-apt

    Summary:

    Right now the demo app declares the annotation processor as a direct dependency. This pulls guava and all other unnecessary dependencies to the demo app.

    This diff switches the demo app to use https://bitbucket.org/hvisser/android-apt, which makes sure the annotation processors are not pulled in as dependencies.

    We should have a runtime artifact in maven() later and update our readme file.

    Test Plan:

    1. ./gradlew :demo:installDebug
    2. use the demo app and everything works.
    opened by kangzhang 6
  • Error while compile release apk with proguard

    Error while compile release apk with proguard

    I got warning message when I build release apk for my app "Warning: com.instagram.common.json.annotation.processor.JsonAnnotationProcessor: can't find referenced field 'javax.annotation.processing.ProcessingEnvironment processingEnv' in program class com.instagram.common.json.annotation.processor.JsonAnnotationProcessor"

    But when I add "-dontwarn com.instagram.common.json.annotation.processor.", it can be fixed. Does not matter if I put "-dontwarn com.instagram.common.json.annotation.processor." in proguard file? Thanks

    opened by willyantows 6
  • Conflict on the JavaWriter class

    Conflict on the JavaWriter class

    The JavaWriter from Square seems to be packaged directly into ig-json-parser jar without being moved or renamed. This seems to cause conflict with other libraries which need a more recent version JavaWriter such as Dagger.

    Why not using an external dependency on JavaWriter instead? At worse repackaging it (at least during the build if this causes later merge issues)?

    opened by rtmvc 6
  • Generated source location

    Generated source location

    Making a separate issue from this because it shouldn't be in the documentation issue...

    Right now the generated source is in demo/igmodel/gen-src/main/java/com/instagram..., it should probably go in demo/build/generated/source/ig-gson/[variant]/com/instagram...

    The current generated source is not flagged by the IDE as generated, so you can edit it and obviously it will be overwritten on next build. If you place the code in build/generated, you get a nice warning like this:

    warning

    opened by jacobtabak 6
  • Does not build with JDK 1.8

    Does not build with JDK 1.8

    I had to download and install JDK 1.7 in order to build the project. Is this a known issue / should it be added to documentation? Or is there something that can be done to get it to work with 1.8?

    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
            at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)
            at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
            at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
            at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
            at com.android.dx.command.dexer.Main.processClass(Main.java:665)
            at com.android.dx.command.dexer.Main.processFileBytes(Main.java:634)
            at com.android.dx.command.dexer.Main.access$600(Main.java:78)
            at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:572)
            at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
            at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
            at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
            at com.android.dx.command.dexer.Main.processOne(Main.java:596)
            at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)
            at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)
            at com.android.dx.command.dexer.Main.run(Main.java:230)
            at com.android.dx.command.dexer.Main.main(Main.java:199)
            at com.android.dx.command.Main.main(Main.java:103)
    ...while parsing com/instagram/common/json/annotation/processor/JsonAnnotationProcessor$1.class
    
    opened by jacobtabak 6
  • Who wrote the upload section of Instagram?

    Who wrote the upload section of Instagram?

    stupid programmers who are not even able to make a simple upload. The stupid developer team of Instagram is not working for the suspand accounts. Ajax request are all wrong, you don't answer any email, so what do you do!

    opened by sajjadef98 1
  • Bintray is shutting down

    Bintray is shutting down

    Currently the link returns https://dl.bintray.com/ezaquarii/android/com/github/instagram/ig-json-parser/runtime/master-SNAPSHOT/maven-metadata.xml returning 404.

    More information about the shut down can be found here: https://blog.gradle.org/jcenter-shutdown

    Please republish the package on maven central or something similar.

    opened by dimka-abramov 0
  • Using with other annotation processor

    Using with other annotation processor

    Hello,

    butterknife is a default library to development, so I must use it!

    But I would like to use json parser.

    And this part of gradle block butterknife:

    compileJava {
      doFirst {
        // Directory should exists before compilation started.
        generatedSourcesDir.mkdirs()
      }
      options.compilerArgs += [
                           '-processor',
                           'com.instagram.common.json.annotation.processor.JsonAnnotationProcessor',
                           '-s',
                           generatedSourcesDir
      ]
    }
    

    What is the proper way to use both libraries together? Others recommended to use ig-json-parser with android-apt but I don't know how can I.

    bg, Larten

    opened by larten 13
  • Allow JsonField to be used as a parameter annotation (enhancement request)

    Allow JsonField to be used as a parameter annotation (enhancement request)

    Some projects have deep class hierarchies where member fields are inaccessible. If JsonField could be applied to arguments, this would be easy to overcome.

    Example:

    class Fuu extends Fu {
        public Fuu(@JsonField(fieldName="le_fu") boolean leFu) {
            super(leFu);
        }
    }
    
    opened by goncalossilva 2
  • Support for case insensitive field names

    Support for case insensitive field names

    It would obviously be a little slower for parsing, but this would provide a huge amount of flexibility. At least making it optional would allow this to be used in cases where the content you are consuming is a little less uniform/well defined.

    enhancement 
    opened by Wavesonics 2
MapNeat is a JVM library written in Kotlin that provides an easy to use DSL (Domain Specific Language) for transforming JSON to JSON, XML to JSON, POJO to JSON in a declarative way.

MapNeat is a JVM library written in Kotlin that provides an easy to use DSL (Domain Specific Language) for transforming JSON to JSON, XML to JSON, POJ

Andrei Ciobanu 59 Sep 17, 2022
A fast JSON parser/generator for Java.

fastjson Fastjson is a Java library that can be used to convert Java Objects into their JSON representation. It can also be used to convert a JSON str

Alibaba 25.1k Dec 31, 2022
High-performance JSON parser

HikariJSON A High-performance JSON parser. HikariJSON is targeted exclusively at Java 8. If you need legacy support, there are several decent librarie

Brett Wooldridge 454 Dec 31, 2022
A simple java JSON deserializer that can convert a JSON into a java object in an easy way

JSavON A simple java JSON deserializer that can convert a JSON into a java object in an easy way. This library also provide a strong object convertion

null 0 Mar 18, 2022
JSON to JSON transformation library written in Java.

Jolt JSON to JSON transformation library written in Java where the "specification" for the transform is itself a JSON document. Useful For Transformin

Bazaarvoice 1.3k Dec 30, 2022
Generate Java types from JSON or JSON Schema and annotates those types for data-binding with Jackson, Gson, etc

jsonschema2pojo jsonschema2pojo generates Java types from JSON Schema (or example JSON) and can annotate those types for data-binding with Jackson 2.x

Joe Littlejohn 5.9k Jan 5, 2023
Essential-json - JSON without fuss

Essential JSON Essential JSON Rationale Description Usage Inclusion in your project Parsing JSON Rendering JSON Building JSON Converting to JSON Refer

Claude Brisson 1 Nov 9, 2021
A 250 lines single-source-file hackable JSON deserializer for the JVM. Reinventing the JSON wheel.

JSON Wheel Have you ever written scripts in Java 11+ and needed to operate on some JSON string? Have you ever needed to extract just that one deeply-n

Roman Böhm 14 Jan 4, 2023
Genson a fast & modular Java <> Json library

Genson Genson is a complete json <-> java conversion library, providing full databinding, streaming and much more. Gensons main strengths? Easy to use

null 212 Jan 3, 2023
Screaming fast JSON parsing and serialization library for Android.

#LoganSquare The fastest JSON parsing and serializing library available for Android. Based on Jackson's streaming API, LoganSquare is able to consiste

BlueLine Labs 3.2k Dec 18, 2022
Reflectionless command line parser

jbock is a command line parser, which uses the same annotation names as JCommander and picocli. However it does not use reflection. It is an annotatio

null 74 Jan 4, 2023
Parser of the table of contents file of the 1C platform syntax helper

Парсер файла оглавления синтакс-помощника платформы 1С Что делает? Парсит вот это: Оглавление представляет собой файл без расширения, лежит в файле sh

null 9 Jan 27, 2022
A Java serialization/deserialization library to convert Java Objects into JSON and back

Gson Gson is a Java library that can be used to convert Java Objects into their JSON representation. It can also be used to convert a JSON string to a

Google 21.7k Jan 8, 2023
A universal types-preserving Java serialization library that can convert arbitrary Java Objects into JSON and back

A universal types-preserving Java serialization library that can convert arbitrary Java Objects into JSON and back, with a transparent support of any kind of self-references and with a full Java 9 compatibility.

Andrey Mogilev 9 Dec 30, 2021
A modern JSON library for Kotlin and Java.

Moshi Moshi is a modern JSON library for Android and Java. It makes it easy to parse JSON into Java objects: String json = ...; Moshi moshi = new Mos

Square 8.7k Dec 31, 2022
Sawmill is a JSON transformation Java library

Update: June 25, 2020 The 2.0 release of Sawmill introduces a breaking change to the GeoIpProcessor to comply with the updated license of the MaxMind

Logz.io 100 Jan 1, 2023
A reference implementation of a JSON package in Java.

JSON in Java [package org.json] Click here if you just want the latest release jar file. Overview JSON is a light-weight language-independent data int

Sean Leary 4.2k Jan 6, 2023
A JSON Schema validation implementation in pure Java, which aims for correctness and performance, in that order

Read me first The current version of this project is licensed under both LGPLv3 (or later) and ASL 2.0. The old version (2.0.x) was licensed under LGP

Java Json Tools 1.5k Jan 4, 2023
Lean JSON Library for Java, with a compact, elegant API.

mJson is an extremely lightweight Java JSON library with a very concise API. The source code is a single Java file. The license is Apache 2.0. Because

Borislav Iordanov 77 Dec 25, 2022