[api2] Fixed encoding/decoding bug