JsonObject to TextComponent

Discussion in 'BungeeCord Plugin Development' started by Astrorious, May 19, 2016.

  1. Hello Everyone!
    ok, I have been looking around for a good way to do this, but the more I look, the harder it is to find a good way of taking a JsonObject (gson) and turning it into a TextComponent (net.md_5)
    It seems to be that I need to use TextComponentSerializer, but the last argument has me a bit stumped, as I cannot find any good examples of it's usage (JsonDeserializationContext from gson). anyone know how to do this without too much hassle?
    Thanks,
    ~Astrorious
    P.S. the other way I could do this is with NMS and using a JSON string, but I have been told by a lot of people that its not a good idea (I would like to stay away from nms if at all possible)
     
    • Friendly Friendly x 1
  2. md_5

    Administrator Developer

    Turn gson to string, string to text component. Only reasonably supported way.
     
    • Useful Useful x 1
    • Creative Creative x 1
  3. I tried this, but I ended up getting the json string sent as a message (the actual text itself rather than the tellraw-style json). Is there a specific method in TextComponent that I need to use?
     
    • Agree Agree x 1
  4. md_5

    Administrator Developer

    ComponentSerializer.parse
     
    • Useful Useful x 1
    • Optimistic Optimistic x 1