Comments (2)
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.
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)
- Is there any option to set one field do not be translated? HOT 4
- It seems broken with atom HOT 3
- undefined function HOT 3
- issues generating json from list of nested records HOT 3
- Automatically create user defined type for record. HOT 1
- Errors when a type mismatches on to_json are not helpful
- Allow to_json to return maps instead of proplists. HOT 6
- Does not support rebar3?
- Unprocessed error HOT 2
- Possible Error HOT 1
- types do not resolve to simplest type HOT 1
- How to use rec2json with a record that has a field with the same name?
- Accessor funs HOT 2
- Error when convert nested list of records HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rec2json.