protocolbuffers / protobuf-javascript

BSD 3-Clause "New" or "Revised" License
375 stars 67 forks source link

Specify custom code per field when .toObject() #102

Closed SmashPlusUltra closed 2 years ago

SmashPlusUltra commented 2 years ago

Is there a way to do a preprocessing of the field before generating the object? For example: proto.MyType.toObject = function(includeInstance, msg) { var f, obj = { nextPaymentDay: new Date(jspb.Message.getFieldWithDefault(msg, 47, "")).toLocaleDateString() , } } It takes a timeStamp and convert in a Date String. The idea is not to have to convert the field in every place It have to be used.

Of course I can change the _pb.js but it's rewritten everytime I make a change.

dibenede commented 2 years ago

Sorry, we have no plans to support this.