I'm sure you can simplify this code using the fact that MapValue and ListValue are case classes.