guochaiqi / google-gson

Automatically exported from code.google.com/p/google-gson
0 stars 0 forks source link

Feature Request: RegExp object support. #291

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have created a XML Schema to JSON converter that is using handwritten code to 
build the JSON representation.

I wanted to factor out that handwritten code and replace it with a library like 
GSON.

Unfortunatly I don't see a way to write a custom serializer that would allow me 
to convert a regular expression into a RegExp object using the /.../ notation.

for example [0-9A-Z]{1,8} would become /[0-9A-Z]{1,8}/

but I don't have an element type available that would allow me to do this. 
Strings are always quoted. I need a way to be able to add RAW data in the 
serialized stream.

Maybe it's not a goal of a JSON payload to support such a thing, but it allows 
me to optimize the use of the schema in the browser.

Original issue reported on code.google.com by david.nouls on 17 Feb 2011 at 9:28

GoogleCodeExporter commented 9 years ago
Can you provide a more detailed code example on what you want to be written out?
Is the output going to be valid JSON?

Original comment by inder123 on 20 May 2011 at 9:56

GoogleCodeExporter commented 9 years ago
No indeed, officially it would not be valid JSON sing a RegExp object is not 
defined in the specs to be correct JSON. In practive however it works fine 
since RegExp is natively supported with the /regexp/ syntax.
Anyway, I no longer need this feature since I implemented a workaround.

Original comment by david.nouls on 1 Jun 2011 at 12:42

GoogleCodeExporter commented 9 years ago
We aren't going to support /regex/ syntax.

Original comment by limpbizkit on 17 Jun 2011 at 9:11