Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  kryonet hide methods from serialization  (Read 1310 times)
0 Members and 1 Guest are viewing this topic.
Offline zidsal

Senior Newbie





« Posted 2013-04-02 11:54:34 »

I have some packets that have helper methods for initalizing such as this

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
   public String reason = "No reason give. Please contact the development team if you see this message!";
   
   private String[] reasonList =
                        {"Invalid Username.",
                         "Invalid Password.",
                         "This account has been banned." ,
                         "The server is currently in maintenance mode."
                        };
   
   public Packet4LoginFailed(int index){
      reason = reasonList[index];
   }


I have registered the classes in the right order in both the server and the client (the registration is done in a shared class). However it errors. If I removed the constructor the packet no longer errors. I have a feeling this is to do with how kryo serializes the class. Is there anyway I can hide the constructor from serialization. I'm presuming there is some kind of annotation, however I couldn't find anything in the kryonet google project page.

edit
the constructor is just 1 example of when I'd like to hide a method Some of my packets have other helper methods to make sure I initialize it properly.
Offline Nate

JGO Kernel


Medals: 149
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #1 - Posted 2013-04-02 14:04:59 »

Kryo requires a no-arg constructor (there are ways around it but that is the simple answer).
https://code.google.com/p/libgdx/wiki/GettingHelp#Exceptions

Offline ra4king

JGO Kernel


Medals: 350
Projects: 3
Exp: 5 years


I'm the King!


« Reply #2 - Posted 2013-04-02 22:06:45 »

Wrong link, Nate. Best thing I could find was this: https://code.google.com/p/kryo/wiki/V1Documentation#Custom_serializers

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Nate

JGO Kernel


Medals: 149
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #3 - Posted 2013-04-03 03:54:30 »

Nope, it was the right link. I wrote that wiki article and I've taken to just linking to it instead of spending time trying to help people help me help them. The OP posted he had a problem that "errors" but never posted the exception, so he gets the link. Smiley

You linked the Kryo v1 docs. The OP is likely on v2.

Offline ra4king

JGO Kernel


Medals: 350
Projects: 3
Exp: 5 years


I'm the King!


« Reply #4 - Posted 2013-04-03 04:35:52 »

Ah I thought you wanted to link to the ways around the no-arg constructor. My bad Tongue

Offline zidsal

Senior Newbie





« Reply #5 - Posted 2013-04-03 12:21:28 »

sorry I didn't reply to this topic sooner. I didn't think I needed to post the error as I knew it was definitely to do with how the class was being registered (as when I removed the helper methods the error disappeared).

anyway I've sorted the probem now by going the simple route and getting rid of the methods.
Offline Nate

JGO Kernel


Medals: 149
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #6 - Posted 2013-04-03 14:03:45 »

If you've ever done tech support, the first thing you do is disregard the self diagnosis of the person you are helping. Smiley

Offline Cero
« Reply #7 - Posted 2013-04-03 14:45:41 »

If you've ever done tech support, the first thing you do is disregard the self diagnosis of the person you are helping. Smiley
yeah doesnt really help though if you know at least as much as the tech support

like when you call to report a problem and they tell you to check the cable... not that I call those kinds of numbers Grin

Offline Nate

JGO Kernel


Medals: 149
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #8 - Posted 2013-04-03 19:13:07 »

If you knew as much as you thought, you wouldn't be calling the tech support. Smiley

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (37 views)
2014-10-17 03:59:02

Norakomi (28 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (28 views)
2014-10-15 16:18:58

TehJavaDev (52 views)
2014-10-14 00:39:48

TehJavaDev (54 views)
2014-10-14 00:35:47

TehJavaDev (42 views)
2014-10-14 00:32:37

BurntPizza (64 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (77 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!