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
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 5, 2023
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 Jan 2, 2023
Manager of progress using Lottie JSON, compatible for Java and Kotlin.

Progress Lottie IGB Manager of progress using Lottie JSON, compatible for Java and Kotlin. Int Top In Bottom Important Info: To create a raw folder: R

Isaac G. Banda 21 Sep 16, 2022
A lightweight Kotlin DSL to render DSL style Json to String.

A lightweight Kotlin DSL to render DSL style Json to String.

null 4 May 5, 2021
xls2json - Read in Excel file (.xls, .xlsx, .xlsm) and output JSON

xls2json Read in Excel file (.xls, .xlsx, .xlsm) and output JSON. Evaluates formulas where possible. Preserve type information from Excel via JSON typ

Tammo Ippen 39 Oct 19, 2022
Modern JSON processor with readable Kotlin syntax.

Kq Modern cross-platform JSON processor with readable Kotlin syntax. cat ~/Desktop/bdb.ndjson | kq '.filter{it.bool("muted")}.sortedBy{it.long("size")

Daniel Demidko 6 Jan 25, 2022
Simple CLI app to convert XML retrieved from a configurable URI to JSON and back

XmlToJsonUtility Simple CLI app written in Kotlin (1.5.31) on Java 11, using Spring Boot. Queries a URI (default) as an XML source. Attempts to valida

Darius Washington 2 Oct 20, 2021
ktlint JSON Lines reporter

ktlint JSON Lines reporter Usage Download the jar and run: ktlint --reporter=jsonlines,artifact=ktlint-jsonlines-reporter.jar Download Either downloa

Anton Musichin 1 Nov 24, 2021
Generate a JSON bookmarks document from a GitHub user

Github to bookmarks This little webapp will generate a JSON bookmarks document from a GitHub user. This is intended to be used with bbt. An instance i

Benoit Lubek 2 Nov 8, 2021
Customizable JSON Schema-based forms for Kotlin and Compose

Kotlin JSON Forms Customizable JSON Schema-based forms for Kotlin and Compose This project aims to reimplement JSON Forms in Kotlin for use in Compose

Copper Leaf 3 Oct 1, 2022
🚀Plugin for Android Studio And IntelliJ Idea to generate Kotlin data class code from JSON text ( Json to Kotlin )

JsonToKotlinClass Hi, Welcome! This is a plugin to generate Kotlin data class from JSON string, in another word, a plugin that converts JSON string to

Seal 2.8k Jan 3, 2023
Android Material Json Form Wizard is a library for creating beautiful form based wizards within your app just by defining json in a particular format.

Android Json Wizard Android Json Wizard is a library for creating beautiful form based wizards within your app just by defining json in a particular f

Vijay Rawat 355 Nov 11, 2022
Images grid JSON | Сетка изображений JSON

Images grid JSON | Сетка изображений JSON Задача Разработать приложение: Приложение должно получать JSON-список ссылок на изображения с сервера по адр

Sefo Notasi 2 Apr 25, 2022
Dynamic-UI-From-JSON - A Sample Android app to show dynamic UI generation from Json

Dynamic UI from JSON Functionality The app's functionality includes: The app gen

Rafsan Ahmad 12 Dec 16, 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 5, 2023
LiteHttp is a simple, intelligent and flexible HTTP framework for Android. With LiteHttp you can make HTTP request with only one line of code! It could convert a java model to the parameter and rander the response JSON as a java model intelligently.

Android network framework: LiteHttp Tags : litehttp2.x-tutorials Website : http://litesuits.com QQgroup : 42960650 , 47357508 Android网络通信为啥子选 lite-htt

马天宇 829 Dec 29, 2022
I was fed up with writing Java classes to mirror json models. So I wrote this Java app to automate the process.

Json2Java I was fed up with writing Java classes to mirror json models. So I wrote this Java app to automate the process. What this tool can do right

Jon F Hancock 303 Oct 8, 2022
malik dawar 87 Sep 18, 2022
Apk parser for java

APK parser lib, for decoding binary XML files, getting APK meta info. Table of Contents Features Get APK-parser Usage 1. APK Info 2. Get Binary XML an

Hsiafan 1.1k Jan 2, 2023
Apk parser for java

APK parser lib, for decoding binary XML files, getting APK meta info. Table of Contents Features Get APK-parser Usage 1. APK Info 2. Get Binary XML an

Hsiafan 1.1k Dec 18, 2022