Created
September 15, 2017 10:39
-
-
Save milechainsaw/b40c3e4f478c5e14a975b6c1d3e81a94 to your computer and use it in GitHub Desktop.
Converter for http://objectbox.io/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.test.objectbox.converters | |
import io.objectbox.converter.PropertyConverter | |
/** | |
* Created by milenkojovanovic on 9/14/17. | |
*/ | |
class StringListConverter : PropertyConverter<List<String>, String> { | |
override fun convertToEntityProperty(databaseValue: String?): List<String> { | |
if (databaseValue == null) return ArrayList() | |
return databaseValue.split(",") | |
} | |
override fun convertToDatabaseValue(entityProperty: List<String>?): String { | |
if (entityProperty == null) return "" | |
if (entityProperty.isEmpty()) return "" | |
val builder = StringBuilder() | |
entityProperty.forEach { builder.append(it).append(",") } | |
builder.deleteCharAt(builder.length - 1) | |
return builder.toString() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment