[ 
https://issues.apache.org/jira/browse/THRIFT-4611?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16573581#comment-16573581
 ] 

Brian Forbis commented on THRIFT-4611:
--------------------------------------

Hmm, maybe I'm wrong but I thought the JSON protocol was entirely custom code 
and doesn't really use JSON.stringify(). I see one reference to it in 
[json_protocol.js|https://github.com/apache/thrift/blob/master/lib/nodejs/lib/thrift/json_protocol.js#L184]
 which seems to be handling values of type object, though it seems strangely 
out of place considering the rest of the code.

Could there be a toReadableJSON() method for this purpose instead?

> NodeJS thrift enums not mappable back to their string values
> ------------------------------------------------------------
>
>                 Key: THRIFT-4611
>                 URL: https://issues.apache.org/jira/browse/THRIFT-4611
>             Project: Thrift
>          Issue Type: Improvement
>          Components: JavaScript - Compiler, Node.js - Compiler
>    Affects Versions: 0.11.0
>            Reporter: Anthony Alayo
>            Priority: Minor
>
> While attempting to build a javascript-based web tool to read encoded thrift 
> objects, I hit a wall. While I was able to decode from a base64 thrift string 
> to an object, all enum fields are only in their numeral representations with 
> no way to reverse them.
>  
> Here is one example, where there is a Common.thrift file containing enums, 
> and an Event.thrift using one of the enums from Common.thrift.
>  
> Here is the generated Event_types.js:
> {code:java}
> var Common_ttypes = require('./Common_types');
> var ttypes = module.exports = {};
> var Event = module.exports.Event = function(args) {
> this.id = null;
> this.type = null;
> ...
> }
> {code}
> Here is the generated Common_types.js
> {code:java}
> var ttypes = module.exports = {};
> ttypes.EventType = {
> 'OUTBOUND' : 0,
> 'INBOUND' : 1,
> }{code}
> While Common_types is being required in Event_types, there is no use of it 
> anywhere. The field type is solely being treated as a number:
> {code:java}
> if (this.type !== null && this.type !== undefined) {
> output.writeFieldBegin('type', Thrift.Type.I32, 3);
> output.writeI32(this.type);
> output.writeFieldEnd();
> }
> {code}
>  
> It seems to be a bug, since I assume from the import that we would expect to 
> use enums instead of numbers. Perhaps this is intended, but if that's the 
> case, could this be made into a feature? The ability to know and display the 
> enum string values instead of a number is a game changer.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to