Skip to content

graalvm支持 #35

@wenshao

Description

@wenshao

陈立兵(雷卷)反馈:

使用 jbang --verbose --native Hello.java 测试发现fastjson2报错。

///usr/bin/env jbang "$0" "$@" ; exit $?
//JAVA 17
//DEPS io.goodforgod:graalvm-hint-processor:0.18.1
//DEPS io.goodforgod:graalvm-hint-annotations:0.18.1
//DEPS com.alibaba.fastjson2:fastjson2:2.0.1

import com.alibaba.fastjson2.JSON;
import io.goodforgod.graalvm.hint.annotation.NativeImageHint;
import io.goodforgod.graalvm.hint.annotation.ReflectionHint;

@NativeImageHint(optionNames = {"--report-unsupported-elements-at-runtime"})
public class Hello {
    public static void main(String... args) throws Exception {
        User user = new User(1, "leijuan");
        // fastjson 2.0
        String jsonText = JSON.toJSONString(user);
        User user2 = JSON.parseObject(jsonText, User.class);
        System.out.println("Fastjson: " + user2.getNick());
    }
}

@ReflectionHint
class User {
    private Integer id;
    private String nick;

    public User() {
    }

    public User(Integer id, String nick) {
        this.id = id;
        this.nick = nick;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getNick() {
        return nick;
    }

    public void setNick(String nick) {
        this.nick = nick;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions