1

As an Eclipse using client-side dev, my colleague just showed me the coolest features in Visual Studio where he copied a JSON string representing a single object and paste special into Visual Studio, then it automagically create a C# class complete with setters and getters. He then took a JSON string representing an array of objects and then did the same workflow. Visual Source save then derived the common fields in the collection and automagically created a C# class.

How do I do this in Eclipse? There is no such thing as Paste Special -> Parse JSON to Class in Eclipse that I know of.

millimoose
  • 39,073
  • 9
  • 82
  • 134
Mark Lapasa
  • 1,644
  • 4
  • 19
  • 37
  • Maybe your IDE has a plugin? – vikingsteve May 16 '13 at 14:43
  • just think about how many times could you use this on your project, for this I wouldn't pay like 700$ or how many is the Visual studio license. It is just a plugin, addon, wich can be developed for Eclipse. I don't like even the visual designer, because they generate unused code, but we are different –  May 16 '13 at 14:46
  • 1
    IMO I don't find a real usage to this. Or would you prefer to program your classes in JSON format? The fact that is *cool* doesn't make it useful. – Luiggi Mendoza May 16 '13 at 14:48
  • Why wouldn't it be useful in the circumstance where the JSON format is already specified? There might be some difficulties inferring the data types but that should be solvable. – vikingsteve May 16 '13 at 14:52
  • 1
    http://stackoverflow.com/questions/1957406/generate-java-class-from-json – Uncle Iroh May 16 '13 at 14:54
  • This would be an incredibly cool feature to have, especially for system integrators. Doesn't come with Eclipse plain-out-the-box though, thats for sure. – Perception May 16 '13 at 20:03
  • @LuiggiMendoza In the absence of a real schema language for JSON, generators like this can at least get you 80% of the way with spitting out boilerplate. The idea would be that you document your schema using a very complete example, then use a similar generator in the languages that consume said JSON. (And even if there isn't a generator available, having a complete example of what to expect in a document is a good idea.) – millimoose May 16 '13 at 21:01

1 Answers1

-1

protostuff could probably fit with your requirements, see http://code.google.com/p/protostuff/ it takes a special language describing the base data structure an produces tidy java classes with annotations.

Automagically deriving structured java classes from schema-less JSON sample data is IMHO a bad idea as you may miss optional fields that are not in your sample.

Steve Oh
  • 1,149
  • 10
  • 18
  • 1
    Seeing as the requirements clearly mention JSON, and protostuff-compiler only mentions handling `.proto` files, this doesn't really fit the requirements at all. – millimoose May 16 '13 at 15:03
  • it says: A serialization library with built-in support for forward-backward compatibility (schema evolution) and validation. available formats: protostuff (native), protobuff, json ... – Steve Oh May 16 '13 at 15:04
  • @millimoose i agree with that – Steve Oh May 16 '13 at 15:08
  • As I understand it, it only supports those formats for (de)serialization. The code generation component only works with the Protocol Buffers IDL. – millimoose May 16 '13 at 15:10