Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

集成在Android项目中报异常,自己想了很多办法没搞定 #11

Closed
qiaokang opened this issue Dec 21, 2016 · 4 comments
Closed

Comments

@qiaokang
Copy link

我试着将Jar放在Android项目中,解析时报异常,自己也试着解决但没有搞定
com.jsoniter.JsonException: javassist.NotFoundException: com.jsoniter.spi.Decoder
不知道是不是跟javassist有关系?

@taowen
Copy link
Contributor

taowen commented Dec 21, 2016

android 支持还要等一等,估计对于android来说最好是搞静态的代码生成。或者纯用反射。今天测了一下,纯反射仍然比jackson快一倍。

@taowen
Copy link
Contributor

taowen commented Dec 22, 2016

搞了一个静态代码生成的方案

https://github.com/json-iterator/java/blob/master/demo/src/main/java/com/jsoniter/demo/codegen/DemoCodegenConfig.java

执行后产生decoder的源代码。执行的目录应该是src/main/java的位置。然后使用的时候

https://github.com/json-iterator/java/blob/master/demo/src/main/java/com/jsoniter/demo/codegen/Demo.java

把执行模式切换为使用静态生成的decoder

JsonIterator.setMode(DecodingMode.STATIC_MODE);

这里的类是代码生成的:https://github.com/json-iterator/java/tree/master/demo/src/main/java/decoder

@taowen
Copy link
Contributor

taowen commented Dec 24, 2016

         <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.5.0</version>
                <executions>
                    <execution>
                        <id>static-codegen</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>java</executable>
                            <workingDirectory>${project.build.sourceDirectory}</workingDirectory>
                            <arguments>
                                <argument>-classpath</argument>
                                <classpath/>
                                <argument>com.jsoniter.StaticCodeGenerator</argument>
                                <argument>com.jsoniter.demo.codegen.DemoCodegenConfig</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

@qiaokang
Copy link
Author

com.jsoniter.JsonException: must execute static code generator in the java source code directory which contains: main/java/com/jsoniter/demo/DemoCodegenConfig.java

不太理解这种方式,产生decoder的源代码的时候报上面的异常信息.有点蒙

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants