1

Is there any chance to get a easy way to sync data, in this case contacts, between the android contentprovider and a JSON-based server?

My problem is, that android uses the cursors and stuff and on the other side I have the JSON-Format. Second problem: the same value have now two different names, so I need a kind of mapping between values in the two different data sources.

My first approach was to define a "User"-Class. Where I would have different methods to fill it with data and different methods to get the data back. The problem is, that with this approach I have to do the mapping between android contentprovider and JSON server in every single method, e.g.

AndroidContact->(Mapping)->User-Object->(Mapping)->JSON-Format

JSON-Format->(Mapping)->-User-Object->(Mapping)->AndroidContact

As you can see, for the whole communication I need to do the mapping at least four times, which is really a pain in the ass, because I'm syncing ALL informations a contact can have, which is quite much.

So I'm searching for a clever way to sync my android contacts with an JSON server, without defining the whole mapping stuff more than once.

Hopefully I could make it clear, what I'm searching for. If not feel free to ask.

Cheers L0rdAli3n

Christoph Haefner
  • 1,093
  • 1
  • 9
  • 25

2 Answers2

0

After another day searching the web for a preexisting solution for my problem (I didn't want to reinvent the wheel) I came up with the following solution:

I added a MappingContentProvider to hold the mapping informations and all those methods filling the User-Class with data or get the data back from it can now use it.

Christoph Haefner
  • 1,093
  • 1
  • 9
  • 25
0

You can use MatrixCursor to return data that you have either in xml or json format.

MatrixCursor : A mutable cursor implementation backed by an array of Objects.

final MatrixCursor cursor = new MatrixCursor(SEARCH_COLUMN_NAMES);              
for (OpenSearchHandler.Result result : results) {                       
     cursor.addRow(new Object[] { result.id, result.title, result.description, result.url });
}
NiTiN
  • 1,022
  • 1
  • 16
  • 25