Skip to content

Instantly share code, notes, and snippets.

@milechainsaw
Created September 15, 2017 10:39
Show Gist options
  • Save milechainsaw/b40c3e4f478c5e14a975b6c1d3e81a94 to your computer and use it in GitHub Desktop.
Save milechainsaw/b40c3e4f478c5e14a975b6c1d3e81a94 to your computer and use it in GitHub Desktop.
Converter for http://objectbox.io/
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