开发者

Map values between different data sources

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 an开发者_StackOverflowd 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


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.


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 });
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜