Giter VIP home page Giter VIP logo

Comments (2)

lordnull avatar lordnull commented on August 25, 2024

There are a couple of problems here. First, the parse transform looks for a record with the same name as the module. So you would need to either create a 'user' module, or renamed the record to 'test_json'. Though if you do the first, you will end up with a collision with the existing 'user' module in the erlang standard library.

Next, the to_json/1 function is put into the same module, so you don't need to call `rec2json:to_json/1' directly, you can instead call '?MODULE:to_json/1'.

-module(user_json).

-compile([{parse_transform, rec2json}]).

-record(user_json, {
        userid :: binary(),
        username :: binary()
}).

-export([test/0]).

test()->
    Record = #user{userid= <<"james">>, username= <<"james chen">>},
    io:format("record=~p~n", [Record]),
    user_json:to_json(Record).

from rec2json.

jamescheng17 avatar jamescheng17 commented on August 25, 2024

Hi lordnull,

after reading your reply, I modified my code
It works correctly now

Thank you for your big help

from rec2json.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.