0

The component I'm working on is changing its datastore from mongo -> mysql. In mongo, you can fit a pojo (with other pojo fields) into a document, not in mysql.

For a particular Object, I'd like to be able to toString() it and store that in a mysql TEXT column.

When I retrieve it, I'd like to be able to MyClass.staticToObject(String stringifiedObj) to get a MyClass instance. Is this possible?

I know I can write a custom toString() and parser but it seems a little tedious/prone to errors.

Is there a faster way?

3
  • 3
    Yeah, serialize it . Commented Oct 19, 2017 at 19:15
  • Are you sure you want to store it in a TEXT column? That would be still thinking in Mongo style, but you're not working with Mongo anymore. Commented Oct 19, 2017 at 19:18
  • @Kayaman, all fields have been extract to their own columns, except this one which has 'sub-documents'. I'm battling time too and this solution seems right. Serialization could work thanks had not thought of that Dave Newton Commented Oct 19, 2017 at 19:21

1 Answer 1

1

Use any JSON library Guava, Jackson f.i. Serialize it to JSON -> store to DB -> retrieve -> deserialize. I think it's pretty common use case for NOSQL DBs. And for you needs you could add 2 static methods to pojo toJson/fromJson.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.